Start/stop script for Red Hat etc.

Questions and Answers on installation, deployment, management, locking, tranasactions of Servoy Application Server

Start/stop script for Red Hat etc.

Postby jonttu- » Thu Jun 03, 2004 2:52 pm

Hi folks,

i was unable to find a proper System V type startup script for Servoy application server, so I wrote my own (actually, pasted together bits and pieces from other scripts).

With this script you can start and stop the application server and query if it's running. Also you can use chkconfig to turn the service on/off. Runlevel changes should work nicely too.

One problem with the script is that there is no "nice" way of shutting down the application server from unix shell? Let's hope it is implemented soon. I'm just killing the processes. This could be disastrous, so the server should still be shut down from the administration console if possible.

All comments are welcome. Especially I wonder if using "kill" to shut down the server really can break something...

DISCLAIMER: Use the code with your own responsibility. Please understand what you're doing, take backups and and test everything before installing it on your production server.

Installation:

AS ROOT..

1) save the script below as /etc/init.d/servoy

2) edit the script to ensure all the variables are correct: SRVUSER = your system's user name to run servoy under, SERVOY_ROOT = servoy installation directory, SERVOY_EXEC = complete path to servoy startup script (servoy_server.sh)

3) edit the servoy_server.sh script to include user dir so the server can find the preferences file. Add "-Duser.dir=$HOME/servoy" just after the word "java".

4) make sure you have created a user account for servoy. Important: you shouldn't run any other processes than servoy application server under this user id.

5) try starting, stopping and restarting the server, like this:
Code: Select all
# /etc/init.d/servoy start
Starting Servoy services:                                  [  OK  ]
# /etc/init.d/servoy restart
Shutting down Servoy services:                             [  OK  ]
Starting Servoy services:                                  [  OK  ]
# /etc/init.d/servoy stop
Shutting down Servoy services:                             [  OK  ]
# /etc/init.d/servoy status
application server is not running


.. and verify with your browser that the server really has started and stopped.

6) if everything seems to work you can now say chkconfig servoy on to install servoy as a service, that starts and stops automatically during runlevel changes (reboot, etc).

Here is the script:

Code: Select all
#! /bin/sh
#
# System startup info for chkconfig
#
# chkconfig: 35 95 5
# description: Starts and stops the Servoy application server
#
# System startup script for the Servoy Application Server
# Verify SRVUSER, SERVOY_ROOT and SERVOY_SERVER and place in /etc/init.d
#
### BEGIN INIT INFO
# Provides: servoy
# Required-Start: $syslog $network $mysql
# Required-Stop:  $syslog $network $mysql
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start Servoy application server.
### END INIT INFO
#

# source some functions
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network

# check for networking
[ "${NETWORKING}" = "no" ] && exit 0

RETVAL=0

# delay is here because it may take time to stop the server
DELAY=2

# user name to run servoy service - do NOT use root because we kill ALL SRVUSER procs!
SRVUSER=servoy

# where to find the executables
SERVOY_ROOT=/home/servoy/servoy
SERVOY_SERVER=$SERVOY_ROOT/servoy_server.sh
FUSER=/sbin/fuser

# make sure they all exist
if [ ! -d $SERVOY_ROOT ]; then echo "cannot find servoy_root path"; exit 0; fi
if [ ! -f $SERVOY_SERVER ]; then echo "cannot find servoy_server command"; exit 0; fi
if [ ! -f $FUSER ]; then echo "cannot find fuser command"; exit 0; fi

start() {
        if [ "`ps -u $SRVUSER -o pid=`" ]; then
                echo -n "application server is already running"; echo_failure; echo; exit 0
        fi
        echo -n "Starting Servoy services: "
        if [ ! -z "$SERVOY_SERVER" ]; then
            # start the server
            su - $SRVUSER -c $SERVOY_SERVER > /dev/null 2>&1 &
        fi
        touch /var/lock/subsys/servoy
        sleep $DELAY
        if [ "`ps -u $SRVUSER -o pid=`" != "" ] && [ -f /var/lock/subsys/servoy ]; then
                echo_success
        else
                echo_failure
        fi
        echo
        return $RETVAL
}

stop() {
        if [ ! "`ps -u $SRVUSER -o pid=`" ]; then
                echo -n "application server is not running"; echo_failure; echo; exit 0
        fi
        echo -n "Shutting down Servoy services: "
        if [ ! -z "$SERVOY_SERVER" ]; then
            # stop the server

       # first we should try a nice way of stopping the server, if possible:
       # su - $SRVUSER -c $SERVOY_SERVER stop > /dev/null 2>&1
      
       # wait a few seconds and then get rude
       # sleep 4
       kill `ps -u $SRVUSER -o pid=`
            sleep $DELAY

            if [ "`ps -u $SRVUSER -o pid=`" ]; then
                # if still running, lets get violent
           kill -9 `ps -u $SRVUSER -o pid=`
            fi

            RETVAL=$?
        fi
        rm -f /var/lock/subsys/servoy
   sleep $DELAY
        if [ "`ps -u $SRVUSER -o pid=`" == "" ] && [ ! -f /var/lock/subsys/servoy ]; then
                echo_success
        else
                echo_failure
        fi
        echo
        return $RETVAL
}
         
status() {
        if [ ! -z "$SERVOY_SERVER" ]; then
            if [ -x $FUSER ]; then 
                _o=`$FUSER $SERVOY_SERVER`
                if [ $? -eq 0 ]; then
                    echo "application server is running"
                    RETVAL=$?
                else
                    echo "application server is not running"
                    RETVAL=$?
                fi
           else
                echo "status unkown  - fuser not found" >&2
           fi   
        else
            echo "status unkown - servoy server not found" >&2
        fi
        return $RETVAL
}

restart() {
        stop
        start
}

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

exit $RETVAL


Love and light,
Joonas
Last edited by jonttu- on Mon Jun 07, 2004 1:45 pm, edited 1 time in total.
jonttu-
 
Posts: 37
Joined: Thu Jun 03, 2004 2:18 pm

Re: Start/stop script for Red Hat etc.

Postby mattman » Fri Jun 04, 2004 7:50 pm

jonttu- wrote:With this script you can start and stop the application server and query if it's running. Also you can use chkconfig to turn the service on/off. Runlevel changes should work nicely too.


VERY COOL!

With the servoy_server.sh script now working when you click restart, this is an awesome addition for those of us working on Linux.

Now all we need to do is create a perl script for integration into Webmin. Maybe someday when I have no more "business work" to do I'll sit down and write one.

Side note: For those of you using Firebird on Linux, I have recently upgraded to 1.5 (which makes some changes in how the Firebird server is configured) It works without a hitch - at least for me it has. Let's hear it for Open Source empowering the small business with Enterprise grade tools!
Matt Petrowsky
mattman
 
Posts: 160
Joined: Wed Aug 06, 2003 8:23 am
Location: Murrieta, CA

Postby jonttu- » Mon Jun 07, 2004 1:47 pm

Installation instructions added to the original post :)

Love and light,
Joonas
jonttu-
 
Posts: 37
Joined: Thu Jun 03, 2004 2:18 pm

Postby sebster » Thu Jul 01, 2004 11:55 am

You can restart the server commandline using a tool which can fetch URL's for example using wget:

Code: Select all
wget http://localhost:8080/servoy-admin/?rf=1


Similarly you can stop the server with:

Code: Select all
wget http://localhost:8080/servoy-admin/?sf=1


You might have to change the host and the port to point to the correct location depending on your installation.
Sebastiaan van Erk
Servoy
sebster
 
Posts: 251
Joined: Thu Apr 24, 2003 10:03 am
Location: Utrecht, The Netherlands

Postby Jan Aleman » Thu Jul 15, 2004 8:04 pm

To have some logging you could consider changing the startline into:

Code: Select all
# start the server
            su - $SRVUSER -c $SERVOY_SERVER > $SERVOY_ROOT/servoy.log 2>&1 &
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth


Return to Servoy Server

Who is online

Users browsing this forum: Google [Bot] and 21 guests

cron