Application Server as a Service in Unix

Running the Application Server as a service or daemon on the machine ensures that service restart automatically when the machine reboots and also provides the capability to start the server with a UNIX shell. In this post, we will create Weblogic  server as a service making it to start at machine reboot in few steps as follows:

Step 1: Create a file to configure the init script with name weblogic inside directory /etc/default/ with content, as follows:

# /etc/default/weblogic script used to configure the init script

# Weblogic Server installation home directory
WLSHOME="/opt/weblogic/wlserver_10.3"

# Weblogic Server sample server
SAMPLESERVER="/samples/domains/wl_server"

# Username password for stopping
USER="weblogic"
PASSWORD="welcome1"

Step 2: Create a file with name weblogic inside directory /etc/init.d/ with content, as follows:

#!/bin/sh

. /etc/default/weblogic

start() {
  ${WLSHOME}${SAMPLESERVER}/bin/startWebLogic.sh &
}

stop() {
  ${WLSHOME}${SAMPLESERVER}/bin/stopWebLogic.sh -username ${USER} -password ${PASSWORD} &
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

 

Step 3: Make weblogic file inside directory /etc/init.d/ as executable

$ cd /etc/init.d/
$ chmod +x weblogic

Step 4: Add the service to the automatic startup system.

$ sudo update-rc.d weblogic defaults