in CentOS, JOnAS, Linux

Starting JOnAS as a Service on Linux

Here is a startup script for JOnAS, on Linux. It is a nice way to automatically start JOnAS when Linux reboots. It is quite trivial to write but I am sure it will turn out useful for anyone who is still not familiar with startup scripts on Linux. Call it jonas and save it in the directory /etc/init.d. You must be root to do that.

#! /bin/bash
# chkconfig: 2345 95 20
# description: Description of the script
# processname: jonas 
#jonas Start the jonas server.

NAME="Jonas 5.2.1"
cd $JONAS_HOME/logs
case "$1" in
    echo -ne "Starting $NAME.\n"
    /bin/su $JONAS_USER -c "$JONAS_HOME/bin/jonas -bg start "

    echo -ne "Stopping $NAME.\n"
    /bin/su $JONAS_USER -c "$JONAS_HOME/bin/jonas stop "

    echo "Usage: /etc/init.d/jonas {start|stop}"
    exit 1

exit 0

Startup and shutdown scripts are located in the directory /etc/init.d which is linked to /etc/rc.d/init.d/
The command chkconfig (available on Red Hat and similar distributions like CentOS) provides a quick way to generate the symbolic links to the appropriate directories for the various run levels :

chkconfig --add jonas 

Symbolic links to /etc/rc.d/init.d/jonas are created in the rc2.d, rc3.d, rc4.d and rc5.d directories. These links are called S95jonas. So it avoids creating all the links manually, one by one :

ln -s /etc/rc.d/init.d/jonas /etc/rc2.d/S95jonas
ln -s /etc/rc.d/init.d/jonas /etc/rc3.d/S95jonas
ln -s /etc/rc.d/init.d/jonas /etc/rc4.d/S95jonas
ln -s /etc/rc.d/init.d/jonas /etc/rc5.d/S95jonas

It also lists the current state of a service:

Do not forget to chmod 755 the file to make it executable.
JOnAS can all also be started or stopped manually in the following way:

/etc/rc.d/init.d/jonas start
/etc/rc.d/init.d/jonas stop

The scripts in /etc/init.d are either “Kill” scripts (they start with a K) or “Start” scripts (they start with a S). They are called with a stop parameter, when invoked as a “Kill” script and called with a start parameter when invoked as a “Start” script. These scripts should be structured as follows:

case "$1" in
   instructions for starting a service go here
   instructions for stopping a service go here