A Sample UNIX rc.d Script

The following is an example of a simple startup script for the GridServer Manager running on a RedHat Linux system:

#!/bin/sh
# Startup script for DataSynapse Manager
#
# Source function library.
. /etc/rc.d/init.d/functions
prog="server"
INSTALLDIR=/opt/TIBCO/DataSynapse/manager
DS_DATA_DIR=/var/TIBCO/DataSynapse
export DS_DATA_DIR
JAVA_HOME=/usr/local/java
export JAVA_HOME
case "$1" in
start)
cd $INSTALLDIR
./server.sh start
;;
stop)
cd $INSTALLDIR
./server.sh stop
;;
restart)
cd $INSTALLDIR
./server.sh stop
./server.sh start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

After creating the above file, place it in /etc/rc.d/init.d/. Your Linux system does not directly run scripts from this directory. Instead, a different directory within /etc/rc.d corresponds to each runlevel of your system. When your system enters a runlevel (for example, during system startup), each script in that runlevel’s associated directory runs and receives the start or stop parameter.

Instead of creating several identical copies of your script, you can create symbolic links in each runlevel directory. Links beginning with K run the script with the stop parameter; those with S run the start parameter. The number at the start of each link dictates the order in which scripts run.

The following is an example of the links created when installing the above script. These links start the GridServer Manager at runlevels 3 and 5 and stop it at runlevels 0, 1, and 6:

lrwxrwxrwx    1 root     root           18 Apr  8 16:26 /etc/rc.d/rc0.d/K02datasynapse -> ../init.d/dsserver
lrwxrwxrwx 1 root root 18 Apr 8 16:27 /etc/rc.d/rc1.d/K02datasynapse -> ../init.d/dsserver
lrwxrwxrwx 1 root root 18 Apr 8 16:27 /etc/rc.d/rc3.d/S98datasynapse -> ../init.d/dsserver
lrwxrwxrwx 1 root root 18 Apr 8 16:27 /etc/rc.d/rc5.d/S98datasynapse -> ../init.d/dsserver
lrwxrwxrwx 1 root root 18 Apr 8 16:27 /etc/rc.d/rc6.d/K02datasynapse -> ../init.d/dsserver