Today I have created an initscript for usage in my server, and I wanted to share it with you. I you have comments, please let me know,

I designed it with this points in mind:
  • The server has to be run as another user as root
  • The server has to be started at bootup, so it had to be compatible with Debian-scripts
  • The script has to do some basic checking at startup/shutdown

As a starting point I used the supplied script with the Linux-serverpackage, hence the given credits. And of course, you may use my part as you wish. It would be nice to include this script in future distributions as the Debian-startup-script.

The only 'unusual' program this script depends on, is 'sudo'. For those unfamiliar with this program I advise to read about it. It's very usefull for most administrators.

Code:
#! /bin/bash
# Copyright (c) 2002 TeamSpeak team   All rights reserved.
#
# Author: Niels Werensteijn 2002
#         Reinder Cuperus 2004
#
 
# MODIFY AS NEEDED:
DIR=/home/tss/tss2_rc2
PID=$DIR/tsserver2.pid
PROCESS=$DIR/server_linux
USER=tss
 
case "$1" in
    start)
        if [ ! -f $PID ]
        then
                sudo -u $USER $PROCESS -PID=$PID
        else
                if kill -CHLD `cat $PID`
                then
                        echo Server already running
                else
                        echo PID-file not deleted, server down
                        sudo -u $USER $PROCESS -PID=$PID
                fi
        fi
        ;;
    stop)
        if [ -f $PID ]
        then
                kill -TERM `cat $PID`
 
                echo -n Waiting for process to go down
                N=0
                while [ -f $PID -a $N -lt 10 ]
                do
                        echo -n .
                        sleep 1
                        N=$(($N+1))
                done
                if [ -f $PID ]
                then
                        echo Failed
                        kill -KILL `cat $PID`
                else
                        echo OK
                fi
        else
                echo "Process ain't running"
        fi
        ;;
    restart)
        $0 stop && $0 start || return=$rc_failed
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac
exit 0