Tuesday, March 17, 2015

WSO2ESB start as a service in Oracle Linux

OS : Oracle Linux Server release 5.9
ESB : wso2esbv4.8.1

requirement was the start the ESB automatically when restart the server. To achieve this create startup script as solution.
Rather than put /etc/rc.locl put script in /etc/ini.d directory and setup as a service.
How to do

create a script to start and stop the server as below


#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
 /usr/share/server/server-up.sh
}

stop() {
    echo "stop"
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0

and set executable permission

chmod +x middleware.sh

and change ownership to root

chmod root middleware.sh

create server-up.sh in /usr/share/server/server directory



#!/bin/bash
#set the JAVA_HOME
export JAVA_HOME=/home/virtusa/jdk1.7.0_51
export PATH=/home/virtusa/jdk1.7.0_51/bin:$PATH

screen -A -m -d -S ESB /bin/sh /home/chathura/Middleware/wso2esb-4.8.1/bin/wso2server.sh

date='date'
echo "started at: "$date>> log


*above script start the sever in screen
* has to set java path here because at running time this environment variable not load
then add the script to run levels

chkconfig --add middleware.sh
chkconfig --level 2345 middleware.sh on

Check the script is indeed enabled - you should see "on" for the levels you selected.

chkconfig --list | grep middleware.sh

Hope this is what you were looking for.



No comments:

Post a Comment