Thursday, May 17, 2012

weblogic as windows service

To CREATE SERVICE
Go to${bea_dir}\wlserver_10.3\server\bin where bea_dir is home directory of weblogic installation.
Create a text file with following values:

echo off
SETLOCAL
set DOMAIN_NAME=base_domain
set USERDOMAIN_HOME=D:\work\wls\user_projects\domains\base_domain
set SERVER_NAME=AdminServer
set WLS_USER=weblogic
set WLS_PW=weblogic1
set PRODUCTION_MODE=false
set ADMIN_URL=http://localhost:7001
set JAVA_VENDOR=Sun (or set JAVA_VM=-hotspot)
set JAVA_HOME=D:\work\wls\jdk160_18
set MEM_ARGS=-Xms256m -Xmx512m
call "D:\work\wls\wlserver_10.3\server\bin\installSvc.cmd"
ENDLOCAL

save and rename to createSvc.cmd

Setting admin url and username password is optional if your domain picks up username/password from boot.propeties (domain_home\servers\AdminServer\security), no need to mention them in the script.

For Jrockit:
set JAVA_VENDOR=BEA
set JAVA_HOME=C:\bea\jrockit_160_05


execute the createSvc.cmd from command prompt so you can check if there are any errors.

This should create service with name of "beasvc sampleDomain_Adminserver_name" in the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

check services under (start - run - services.msc) to find your service with beasvc prefix. change it to automatic and start the service and check logs.

INCLUDING CLASSPATH
If you have variables set in classpath which need to be included, edit the installSvc.cmd and look for the line where it calls commenv and replace it with setdomainEnv path.

call "%WL_HOME%\common\bin\commEnv.cmd"

TO REMOVE SERVICE
Go to${bea_dir}\wlserver_10.3\server\bin where bea_dir is home directory of weblogic installation.
Create a text file with following values:

echo off
SETLOCAL
set DOMAIN_NAME=base_domain
set SERVER_NAME=AdminServer
call "D:\work\wls\wlserver_10.3\server\bin\uninstallSvc.cmd"
ENDLOCAL

save and rename to removeSvc.cmd
execute the createSvc.cmd from command prompt so you can check if there are any errors.
(details should be the same as that of createSvc.cmd)


TO CHANGE SERVICE NAME
take a backup of the installSvc.cmd
edit installSvc.cmd and look for beasvc and change the name you wanted to.
"%WL_HOME%\server\bin\beasvc" -install -svcname:"beasvc %DOMAIN_NAME%_%SERVER_NAME%"

TO ENABLE MANAGED SERVICE TO START AFTER ADMIN SERVICE
 make a copy of installSvc.cmd say installSvc2.cmd
edit installSvc2.cmd and make it dependent on admin server script

for example

rem *** Install the service
"%WL_HOME%\server\bin\beasvc" -install -svcname:"ROBIN_%DOMAIN_NAME%_%SERVER_NAME%" -depend:"beasvcAdminService"

so now managed service will depend on admin service before starting.
----------------------------------------------------
1> If you get the below error in the server log

javax.naming.ServiceUnavailableException [Root exception is java.rmi.NoSuchObjectException: The object identified by: '31' could not be found. Either it was has not been exported or it has been collected by the distributed garbage collector.]

remove the service by removeSvc.cmd
edit createSvc.cmd
remove line          set ADMIN_URL=http://localhost:7001
save and run.
----------------------------------------------------
2>  If you get the below error in the server log

<BEA-150000> <An error occurred while establishing a connection

javax.naming.ServiceUnavailableException [Root exception is java.rmi.NoSuchObjectException: The object identified by: '31' could not be found.  Either it was has not been exported or it has been collected by the distributed garbage collector.]

Caused By: java.rmi.NoSuchObjectException: The object identified by: '31' could not be found.  Either it was has not been exported or it has been collected by the distributed garbage collector  

ensure the user has admin rights to the box
remove the service by removeSvc.cmd
edit createSvc.cmd
remove line          set ADMIN_URL=http://localhost:7001
save and run. 
----------------------------------------------------
3>  If you get the below error
'oracle.fabric.common.classloaderurl.handler' is not recognized as an internal or external command

Double quotation marks break the command syntax.

In the installSvc.cmd,
Change the %JAVA_OPTIONS% to \"%JAVA_OPTIONS%\"
(have to add \"  \")

For example
set CMDLINE="%JAVA_VM% %MEM_ARGS% %JAVA_OPTIONS% -classpath
will be come
set CMDLINE="%JAVA_VM% %MEM_ARGS% \"%JAVA_OPTIONS%\" -classpath

Doc ID 1276229.
----------------------------------------------------
To debug:
Go to the installSvc.cmd file and right at the location where you call the beasvc.exe file, insert the following options.

-debug –log:”path to log.txt”

So the entire string would look something like this.

"%WL_HOME%\server\bin\beasvc" –install  -debug  -log:c:\path.txt -svcname:"beasvc %DOMAIN_NAME%_%SERVER_NAME%" -javahome:"%JAVA_HOME%" -execdir:"%USERDOMAIN_HOME%" -maxconnectretries:"%MAX_CONNECT_RETRIES%" -host:"%HOST%" -port:"%PORT%" -extrapath:"%EXTRAPATH%" -password:"%WLS_PW%" -cmdline:%CMDLINE%


Also you can debug by traversing to the folder containing beasvc.exe
*\wlserver_10.3\server\bin> beasvc -debug "affected windows service name" 

Windows service log rotation
http://docs.oracle.com/cd/E14571_01/web.1111/e13708/winservice.htm#i1193313

1 comment:

Tim said...

Does this also work for managed servers?