WSO2 Init Script (with status)

I’ve been stuck working with wso2 products lately, can’t say I’m terribly fond of them, but what can you do.

It turns out that there are no good init scripts for the wso2 servers, and all the ones I found didn’t have a status, so I whipped one up. You can use the same script for all of them, just change the product home to whatever product you’re using.

#!/bin/bash
# wso2AS WSO2 App Server
#
# chkconfig: 345 70 30
# description: WSO2 Application Server
# processname: wso2as
#
# Source function library.
. /etc/init.d/functions
RETVAL=0
ASHOME="/opt/wso2/as"
killproc() { # kill the named process(es)
 pid=`/bin/ps -ef | /bin/grep $1 |
 /bin/grep -v grep | /bin/grep -v /bin/sh |
 /bin/awk '{print $2}'`
 if [ "${pid}" != "" ] ; then
 kill -TERM ${pid} > /dev/null 2>&1
 fi
}
start() {
 echo -n "Starting WSO2 App Server: "
 su - wso2usr -c "$ASHOME/bin/wso2server.sh > /tmp/wso2appsvr.bootlog 2>&1 &"
 RCODE=$?
 touch /var/lock/subsys/wso2as
 return $RCODE
}
stop() {
 echo -n "Shutting down WSO2 App Server: "
 killproc "$ASHOME"
 rm -f /var/lock/subsys/wso2as
 return 0
}
status() {
 pid=`/bin/ps -ef | /bin/grep "$ASHOME" |
 /bin/grep -v grep | /bin/grep -v /bin/sh |
 /bin/awk '{print $2}'`
 if [ "${pid}" != "" ] ; then
 echo "AS Is running"
 return 0
 fi
 return 1
}
case "$1" in
 start)
 start
 ;;
 stop)
 stop
 ;;
 restart)
 stop
 start
 ;;
 status)
 status
 ;;
 *)
 echo "Usage: <servicename> {start|stop|restart}"
 exit 1
 ;;
esac
exit $?

This entry was posted in Technical and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *