Startup script linux

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m
(Undo revision 16911 by Tedd (Talk))
Line 1: Line 1:
−
== /etc/init.d script for Linux ==
+
== /etc/init.d script for Linux ==
  
−
=== Instructions ===
+
=== Instructions ===
  
 
Tested on Debian 5. CHUIDS user to opensim user. Supports: start, stop, restart, status  
 
Tested on Debian 5. CHUIDS user to opensim user. Supports: start, stop, restart, status  
Line 13: Line 13:
 
NOTE: stop-command currently doesn't work properly (it doesn't do a soft shutdown). It will kill OpenSim first with kill pid, then kill -9 pid. So make sure you have saved your data. :)  
 
NOTE: stop-command currently doesn't work properly (it doesn't do a soft shutdown). It will kill OpenSim first with kill pid, then kill -9 pid. So make sure you have saved your data. :)  
  
−
=== Script ===
+
=== Script ===
−
<pre>#! /bin/sh
+
−
### BEGIN INIT INFO
+
−
# Provides: OpenSim
+
−
# Required-Start: $local_fs $network
+
−
# Required-Stop: $local_fs
+
−
# Default-Start: 2 3 4 5
+
−
# Default-Stop: 0 1 6
+
−
# Short-Description: Tedds OpenSim init.d-script
+
−
### END INIT INFO
+
−
# Put script in /etc/init.d/
+
−
# then execute: update-rc.d opensim defaults
+
  
−
set -e
+
<code></code>
  
−
#
+
#! /bin/sh
−
# Directories
+
### BEGIN INIT INFO
−
#
+
# Provides:          OpenSim
−
# Location of OpenSim installation
+
# Required-Start:    $local_fs $network
−
DIR=/home/opensim/OpenSim/bin/
+
# Required-Stop:    $local_fs
−
# Different PID dir?
+
# Default-Start:    2 3 4 5
−
PIDDIR=$DIR
+
# Default-Stop:      0 1 6
 +
# Short-Description: Tedds OpenSim init.d-script
 +
### END INIT INFO
  
−
USER=opensim
+
# Put script in /etc/init.d/
−
SERVICES="OpenSim.Grid.UserServer.exe OpenSim.Server.exe OpenSim.exe"
+
# then execute: update-rc.d opensim defaults
  
−
#
+
set -e
−
# Kill values (in seconds)
+
 
−
#
+
#
−
# How long between each service being started
+
# Directories
−
DELAY_STARTUP=10
+
#
−
# How long between each service is sent shutdown command
+
# Location of OpenSim installation
−
DELAY_KILL=10
+
DIR=/home/opensim/OpenSim/bin/
−
# After shutdown has been sent to all we do another loop with "kill", then "kill -9". How long between "kill" and "kill -9".
+
# Different PID dir?
−
DELAY_FORCEKILL=10
+
PIDDIR=$DIR
  
 +
USER=opensim
 +
SERVICES="OpenSim.Grid.UserServer.exe OpenSim.Server.exe OpenSim.exe"
 +
 +
#
 +
# Kill values (in seconds)
 +
#
 +
# How long between each service being started
 +
DELAY_STARTUP=10
 +
# How long between each service is sent shutdown command
 +
DELAY_KILL=10
 +
# After shutdown has been sent to all we do another loop with "kill", then "kill -9". How long between "kill" and "kill -9".
 +
DELAY_FORCEKILL=10
 +
 +
#
 +
# Info on service handled by this script
 
#
 
#
−
# Info on service handled by this script
+
# Name of service
−
#
+
NAME=opensim
−
# Name of service
+
# Description of service
−
NAME=opensim
+
DESC="OpenSim Server"
−
# Description of service
+
−
DESC="OpenSim Server"
+
  
−
# Binaries
+
# Binaries
−
SCREEN=/usr/bin/screen
+
SCREEN=/usr/bin/screen
−
MONO=/usr/bin/mono
+
MONO=/usr/bin/mono
  
−
###########################
+
###########################
−
##### START OF SCRIPT #####
+
##### START OF SCRIPT #####
−
###########################
+
###########################
  
−
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
+
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
  
−
&lt;br&gt;
+
<br>
  
−
# Load LSB log functions
+
# Load LSB log functions
−
_lsbFile=""
+
_lsbFile=""
−
if [ -e /etc/debian_version ]; then
+
if [ -e /etc/debian_version ]; then
−
_lsbFile="/lib/lsb/init-functions"
+
    _lsbFile="/lib/lsb/init-functions"
−
if [ -f $_lsbFile ]; then
+
    if [ -f $_lsbFile ]; then
−
. $_lsbFile
+
        . $_lsbFile
−
else
+
    else
−
echo This script requires LSB init-functions file which doesn't exist: $_lsbFile
+
        echo This script requires LSB init-functions file which doesn't exist: $_lsbFile
−
exit 1
+
        exit 1
−
fi
+
    fi
−
else
+
else
−
# [ -e /etc/init.d/functions ]&amp;nbsp;; then
+
# [ -e /etc/init.d/functions ]&nbsp;; then
−
_lsbFile="/etc/init.d/functions"
+
    _lsbFile="/etc/init.d/functions"
−
if [ -e $_lsbFile ]; then
+
    if [ -e $_lsbFile ]; then
−
. $_lsbFile
+
        . $_lsbFile
−
else
+
    else
−
echo This script requires LSB init-functions file which doesn't exist: $_lsbFile
+
        echo This script requires LSB init-functions file which doesn't exist: $_lsbFile
−
exit 1
+
        exit 1
−
fi
+
    fi
−
fi
+
fi
  
−
# Lets use fancy output
+
# Lets use fancy output
−
log_use_fancy_output
+
log_use_fancy_output
  
−
# Check that target directory exists
+
# Check that target directory exists
−
if test&amp;nbsp;! -d "$DIR"; then
+
if test&nbsp;! -d "$DIR"; then
−
log_failure_msg "$NAME" "Target directory \"$DIR\" does not exist. Can not continue."
+
    log_failure_msg "$NAME" "Target directory \"$DIR\" does not exist. Can not continue."
−
exit 1
+
    exit 1
−
fi
+
fi
  
−
# Create a reverse order for shutdown
+
# Create a reverse order for shutdown
−
SERVICES_REVERSE=""
+
SERVICES_REVERSE=""
−
reverse() { SERVICES_REVERSE="$9 $8 $7 $6 $5 $4 $3 $2 $1"; }
+
reverse() { SERVICES_REVERSE="$9 $8 $7 $6 $5 $4 $3 $2 $1"; }
−
reverse $SERVICES
+
reverse $SERVICES
  
−
# Check if a service is running
+
# Check if a service is running
−
isrunning() {  
+
isrunning() {  
−
ISRUNNING="0"
+
    ISRUNNING="0"
−
# Do we have PID-file?
+
    # Do we have PID-file?
−
if [ -f "$PIDDIR/$1.pid" ]; then
+
    if [ -f "$PIDDIR/$1.pid" ]; then
−
# Check if proc is running
+
        # Check if proc is running
−
pid=`cat "$PIDDIR/$1.pid" 2&amp;gt; /dev/null`
+
        pid=`cat "$PIDDIR/$1.pid" 2&gt; /dev/null`
−
if [ "$pid"&amp;nbsp;!= "" ]; then
+
        if [ "$pid"&nbsp;!= "" ]; then
−
if [ -d /proc/$pid ]; then
+
            if [ -d /proc/$pid ]; then
−
# Process is running
+
                # Process is running
−
ISRUNNING="1"
+
                ISRUNNING="1"
−
fi
+
            fi
−
fi
+
        fi
−
fi
+
    fi
−
#ISRUNNING="0"
+
    #ISRUNNING="0"
−
}
+
}
−
 
+
−
#
+
−
# Process commands
+
−
#
+
−
case "$1" in
+
−
start)
+
−
# Start all services one by one
+
−
for server in $SERVICES; do
+
−
log_daemon_msg "Starting $NAME" "$server"
+
  
−
isrunning $server
+
#
−
case "$ISRUNNING" in
+
# Process commands
−
1) log_progress_msg "Process already started. Please stop first"; log_end_msg 1&amp;nbsp;;;
+
#
−
0)  
+
case "$1" in
−
# Process is not running
+
start)
−
# Start process and sleep...
+
    # Start all services one by one
−
exefile="/tmp/exe.OpenSim.$server.sh"
+
    for server in $SERVICES; do
 +
        log_daemon_msg "Starting $NAME" "$server"
  
−
# Need to make external file, had big problems with screen params
+
        isrunning $server
−
echo \#\!/bin/bash &amp;gt; $exefile
+
        case "$ISRUNNING" in
−
echo cd $DIR &amp;gt;&amp;gt; $exefile
+
            1) log_progress_msg "Process already started. Please stop first"; log_end_msg 1&nbsp;;;
−
echo $MONO $server &amp;gt;&amp;gt; $exefile
+
            0)
−
chmod +x $exefile
+
                # Process is not running
 +
                # Start process and sleep...
 +
                exefile="/tmp/exe.OpenSim.$server.sh"
  
−
cmd_screen="screen -S $server -d -m $exefile"
+
                # Need to make external file, had big problems with screen params
−
start-stop-daemon --start -b -x /bin/su -m --pidfile=/tmp/su.$server.pid --chdir "$DIR" -- - $USER "-c $cmd_screen"
+
                echo \#\!/bin/bash &gt; $exefile
 +
                echo cd $DIR &gt;&gt; $exefile
 +
                echo $MONO $server &gt;&gt; $exefile
 +
                chmod +x $exefile
  
−
# Delay between services that are started
+
                cmd_screen="screen -S $server -d -m $exefile"
−
sleep $DELAY_STARTUP
+
                start-stop-daemon --start -b -x /bin/su -m --pidfile=/tmp/su.$server.pid --chdir "$DIR" -- - $USER "-c $cmd_screen"
  
−
rm $exefile 2&amp;gt; /dev/null
+
                # Delay between services that are started
 +
                sleep $DELAY_STARTUP
  
−
# Make PID-file
+
                rm $exefile 2&gt; /dev/null
−
ps afxu | grep "mono $server" | grep -iEv "grep|screen" | awk {'print $2'} &amp;gt; "$PIDDIR/$server.pid"
+
  
−
isrunning $server
+
                # Make PID-file
−
case "$ISRUNNING" in
+
                ps afxu | grep "mono $server" | grep -iEv "grep|screen" | awk {'print $2'} &gt; "$PIDDIR/$server.pid"
−
1)
+
−
# Process started ok
+
−
#log_progress_msg "Success";
+
−
log_end_msg 0
+
−
&amp;nbsp;;;
+
−
0)
+
−
# Process didn't start... remove pid-file
+
−
rm "$PIDDIR/$server.pid" 2&amp;gt; /dev/null
+
−
#log_progress_msg "Failure";
+
−
log_end_msg 1
+
−
&amp;nbsp;;;
+
−
esac
+
−
&amp;nbsp;;;
+
−
esac
+
  
−
done
+
                isrunning $server
−
&amp;nbsp;;;
+
                case "$ISRUNNING" in
 +
                    1)
 +
                        # Process started ok
 +
                        #log_progress_msg "Success";
 +
                        log_end_msg 0
 +
                        &nbsp;;;
 +
                    0)
 +
                        # Process didn't start... remove pid-file
 +
                        rm "$PIDDIR/$server.pid" 2&gt; /dev/null
 +
                        #log_progress_msg "Failure";
 +
                        log_end_msg 1
 +
                        &nbsp;;;
 +
                esac
 +
                &nbsp;;;
 +
        esac
  
−
&lt;br&gt;
+
    done
 +
    &nbsp;;;
  
−
stop)
+
<br>
−
_killCount=0
+
  
−
for server in $SERVICES_REVERSE; do
+
stop)
−
log_daemon_msg "Stopping $NAME" "$server"
+
    _killCount=0
  
−
isrunning $server
+
    for server in $SERVICES_REVERSE; do
−
case "$ISRUNNING" in
+
        log_daemon_msg "Stopping $NAME" "$server"
−
1)
+
−
_killCount=`expr $_killCount + 1`
+
−
log_progress_msg "Sending shutdown command:";
+
  
−
# We add some backspaces to the command in case something is on the console already
+
        isrunning $server
−
echo `screen -S $server -X stuff \"  
+
        case "$ISRUNNING" in
 +
        1)
 +
            _killCount=`expr $_killCount + 1`
 +
            log_progress_msg "Sending shutdown command:";
  
−
# Wait for it to shut down...
+
            # We add some backspaces to the command in case something is on the console already
−
sleep $DELAY_KILL
+
            echo `screen -S $server -X stuff \"                           
  
−
isrunning $server
+
            # Wait for it to shut down...
−
case "$ISRUNNING" in
+
            sleep $DELAY_KILL
−
1) log_progress_msg "is still running."; log_end_msg 0&amp;nbsp;;;
+
−
0) log_progress_msg "has been shutdown"; log_end_msg 0&amp;nbsp;;;
+
−
esac
+
  
−
&amp;nbsp;;;
+
            isrunning $server
−
0)  
+
            case "$ISRUNNING" in
−
log_progress_msg "is not running"; log_end_msg 0
+
                1) log_progress_msg "is still running."; log_end_msg 0&nbsp;;;
−
&amp;nbsp;;;
+
                0) log_progress_msg "has been shutdown"; log_end_msg 0&nbsp;;;
−
esac
+
            esac
  
−
done
+
            &nbsp;;;
 +
        0)
 +
            log_progress_msg "is not running"; log_end_msg 0
 +
            &nbsp;;;
 +
        esac
  
−
# Check if any procs are still running
+
    done
−
for server in $SERVICES; do
+
−
isrunning $server
+
−
case "$ISRUNNING" in
+
−
1)
+
−
log_warning_msg "Stopping $NAME" "$server is still running: Forcing kill"
+
−
echo `kill $pid 2&amp;gt; /dev/null`;
+
−
sleep $DELAY_FORCEKILL
+
−
echo `kill -9 $pid 2&amp;gt; /dev/null`;
+
−
sleep 1
+
  
−
# Now check again if it is still running...
+
    # Check if any procs are still running
−
isrunning $server
+
    for server in $SERVICES; do
−
case "$ISRUNNING" in
+
        isrunning $server
−
0) log_progress_msg "Success"; log_end_msg 0&amp;nbsp;;;
+
        case "$ISRUNNING" in
−
1) log_progress_msg "Process is still running... Even after \"kill -9 $pid\". WOW..."; log_end_msg 0&amp;nbsp;;;
+
        1)  
−
esac
+
            log_warning_msg "Stopping $NAME" "$server is still running: Forcing kill"
−
&amp;nbsp;;;
+
            echo `kill $pid 2&gt; /dev/null`;
−
0)
+
            sleep $DELAY_FORCEKILL
−
#log_progress_msg "";
+
            echo `kill -9 $pid 2&gt; /dev/null`;
−
&amp;nbsp;;;
+
            sleep 1
−
esac
+
−
done
+
  
−
log_begin_msg "$NAME: All done (killed $_killCount procs)"; log_end_msg 0
+
            # Now check again if it is still running...
 +
            isrunning $server
 +
            case "$ISRUNNING" in
 +
                0) log_progress_msg "Success"; log_end_msg 0&nbsp;;;
 +
                1) log_progress_msg "Process is still running... Even after \"kill -9 $pid\". WOW..."; log_end_msg 0&nbsp;;;
 +
            esac
 +
            &nbsp;;;
 +
        0)
 +
            #log_progress_msg "";
 +
            &nbsp;;;
 +
        esac
 +
    done
  
−
&amp;nbsp;;;
+
    log_begin_msg "$NAME: All done (killed $_killCount procs)"; log_end_msg 0
  
−
&lt;br&gt;
+
    &nbsp;;;
  
−
&lt;br&gt;
+
<br>
  
−
status)
+
<br>
−
# Count how many processes we need
+
−
PROCCOUNT=0
+
−
for i in $SERVICES; do
+
−
PROCCOUNT=`expr $PROCCOUNT + 1`
+
−
done
+
  
−
# Go through server PID files and count how many are running
+
status)
−
log_begin_msg "$NAME: Running processed:"
+
    # Count how many processes we need
−
_pidCount=0
+
    PROCCOUNT=0
−
for server in $SERVICES; do
+
    for i in $SERVICES; do
 +
        PROCCOUNT=`expr $PROCCOUNT + 1`
 +
    done
  
−
isrunning $server
+
    # Go through server PID files and count how many are running
−
case "$ISRUNNING" in
+
    log_begin_msg "$NAME: Running processed:"
−
1)
+
    _pidCount=0
−
# This server is running
+
    for server in $SERVICES; do
−
_pidCount=`expr $_pidCount + 1`
+
−
log_progress_msg "$server"
+
−
&amp;nbsp;;;
+
−
0)
+
−
&amp;nbsp;;;
+
−
esac
+
−
done
+
  
−
log_begin_msg " ($_pidCount of $PROCCOUNT processes are running)"; log_end_msg 0
+
        isrunning $server
 +
        case "$ISRUNNING" in
 +
            1)
 +
                # This server is running
 +
                _pidCount=`expr $_pidCount + 1`
 +
                log_progress_msg "$server"
 +
                &nbsp;;;
 +
            0)
 +
                &nbsp;;;
 +
        esac
 +
    done
  
−
# Check if running proc count matches requires proc count
+
    log_begin_msg " ($_pidCount of $PROCCOUNT processes are running)"; log_end_msg 0
−
log_begin_msg "$NAME is"
+
 
−
if [ $_pidCount -eq $PROCCOUNT ]; then
+
    # Check if running proc count matches requires proc count
−
log_progress_msg "running"; log_end_msg 0
+
    log_begin_msg "$NAME is"
−
exit 0
+
    if [ $_pidCount -eq $PROCCOUNT ]; then
−
else
+
        log_progress_msg "running"; log_end_msg 0
−
log_progress_msg "NOT running"; log_end_msg 0
+
        exit 0
−
exit 1
+
    else
−
fi
+
        log_progress_msg "NOT running"; log_end_msg 0
−
&amp;nbsp;;;
+
        exit 1
 +
    fi
 +
    &nbsp;;;
  
−
restart)
+
restart)
−
$0 stop
+
    $0 stop
−
$0 start
+
    $0 start
−
&amp;nbsp;;;
+
    &nbsp;;;
−
*)
+
*)
−
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" &amp;gt;&amp;amp;2
+
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" &gt;&amp;2
−
exit 1
+
    exit 1
−
&amp;nbsp;;;
+
    &nbsp;;;
−
esac
+
esac
  
−
exit 0
+
exit 0
−
</pre>
+

Revision as of 04:52, 5 March 2010

/etc/init.d script for Linux

Instructions

Tested on Debian 5. CHUIDS user to opensim user. Supports: start, stop, restart, status

To implement: Type: cat > /etc/init.d/opensim Paste in script from this page Press: CTRL+D Type: chmod +x /etc/init.d/opensim Script should now be located on server and be executable.

Type: update-rc.d opensim defaults Script should now be in your startup.

Modify header in script to adapt it to your installation folder and user.

NOTE: stop-command currently doesn't work properly (it doesn't do a soft shutdown). It will kill OpenSim first with kill pid, then kill -9 pid. So make sure you have saved your data. :)

Script

#! /bin/sh
### BEGIN INIT INFO
# Provides:          OpenSim
# Required-Start:    $local_fs $network 
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Tedds OpenSim init.d-script
### END INIT INFO
# Put script in /etc/init.d/
# then execute: update-rc.d opensim defaults
set -e
#
# Directories
#
# Location of OpenSim installation
DIR=/home/opensim/OpenSim/bin/
# Different PID dir?
PIDDIR=$DIR
USER=opensim
SERVICES="OpenSim.Grid.UserServer.exe OpenSim.Server.exe OpenSim.exe"
#
# Kill values (in seconds)
#
# How long between each service being started
DELAY_STARTUP=10
# How long between each service is sent shutdown command
DELAY_KILL=10
# After shutdown has been sent to all we do another loop with "kill", then "kill -9". How long between "kill" and "kill -9".
DELAY_FORCEKILL=10
#
# Info on service handled by this script
# Name of service
NAME=opensim
# Description of service
DESC="OpenSim Server"
# Binaries
SCREEN=/usr/bin/screen
MONO=/usr/bin/mono
###########################
##### START OF SCRIPT #####
###########################
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"


# Load LSB log functions
_lsbFile=""
if [ -e /etc/debian_version ]; then
    _lsbFile="/lib/lsb/init-functions"
    if [ -f $_lsbFile ]; then
        . $_lsbFile
    else
        echo This script requires LSB init-functions file which doesn't exist: $_lsbFile
        exit 1
    fi
else
# [ -e /etc/init.d/functions ] ; then
    _lsbFile="/etc/init.d/functions"
    if [ -e $_lsbFile ]; then
        . $_lsbFile
    else
        echo This script requires LSB init-functions file which doesn't exist: $_lsbFile
        exit 1
    fi
fi
# Lets use fancy output
log_use_fancy_output
# Check that target directory exists
if test ! -d "$DIR"; then
    log_failure_msg "$NAME" "Target directory \"$DIR\" does not exist. Can not continue."
    exit 1
fi
# Create a reverse order for shutdown
SERVICES_REVERSE=""
reverse() { SERVICES_REVERSE="$9 $8 $7 $6 $5 $4 $3 $2 $1"; }
reverse $SERVICES
# Check if a service is running
isrunning() { 
    ISRUNNING="0"
    # Do we have PID-file?
    if [ -f "$PIDDIR/$1.pid" ]; then
        # Check if proc is running
        pid=`cat "$PIDDIR/$1.pid" 2> /dev/null`
        if [ "$pid" != "" ]; then
            if [ -d /proc/$pid ]; then
                # Process is running
                ISRUNNING="1"
            fi
        fi
    fi
    #ISRUNNING="0"
}
#
# Process commands
#
case "$1" in
start)
    # Start all services one by one
    for server in $SERVICES; do
        log_daemon_msg "Starting $NAME" "$server"
        isrunning $server
        case "$ISRUNNING" in
            1) log_progress_msg "Process already started. Please stop first"; log_end_msg 1 ;;
            0) 
                # Process is not running
                # Start process and sleep...
                exefile="/tmp/exe.OpenSim.$server.sh"
                # Need to make external file, had big problems with screen params
                echo \#\!/bin/bash > $exefile
                echo cd $DIR >> $exefile
                echo $MONO $server >> $exefile
                chmod +x $exefile
                cmd_screen="screen -S $server -d -m $exefile"
                start-stop-daemon --start -b -x /bin/su -m --pidfile=/tmp/su.$server.pid --chdir "$DIR" -- - $USER "-c $cmd_screen"
                # Delay between services that are started
                sleep $DELAY_STARTUP
                rm $exefile 2> /dev/null
                # Make PID-file
                ps afxu | grep "mono $server" | grep -iEv "grep|screen" | awk {'print $2'} > "$PIDDIR/$server.pid"
                isrunning $server
                case "$ISRUNNING" in
                    1) 
                        # Process started ok
                        #log_progress_msg "Success"; 
                        log_end_msg 0 
                        ;;
                    0) 
                        # Process didn't start... remove pid-file
                        rm "$PIDDIR/$server.pid" 2> /dev/null
                        #log_progress_msg "Failure"; 
                        log_end_msg 1 
                        ;;
                esac
                ;;
        esac
    done
    ;;


stop)
    _killCount=0
    for server in $SERVICES_REVERSE; do
        log_daemon_msg "Stopping $NAME" "$server"
        isrunning $server
        case "$ISRUNNING" in
        1) 
            _killCount=`expr $_killCount + 1`
            log_progress_msg "Sending shutdown command:"; 
            # We add some backspaces to the command in case something is on the console already
            echo `screen -S $server -X stuff \"                             
            # Wait for it to shut down...
            sleep $DELAY_KILL
            isrunning $server
            case "$ISRUNNING" in
                1) log_progress_msg "is still running."; log_end_msg 0 ;;
                0) log_progress_msg "has been shutdown"; log_end_msg 0 ;;
            esac
            ;;
        0) 
            log_progress_msg "is not running"; log_end_msg 0
            ;;
        esac
    done
    # Check if any procs are still running
    for server in $SERVICES; do
        isrunning $server
        case "$ISRUNNING" in
        1) 
            log_warning_msg "Stopping $NAME" "$server is still running: Forcing kill"
            echo `kill $pid 2> /dev/null`;
            sleep $DELAY_FORCEKILL
            echo `kill -9 $pid 2> /dev/null`;
            sleep 1
            # Now check again if it is still running...
            isrunning $server
            case "$ISRUNNING" in
                0) log_progress_msg "Success"; log_end_msg 0 ;;
                1) log_progress_msg "Process is still running... Even after \"kill -9 $pid\". WOW..."; log_end_msg 0 ;;
            esac
            ;;
        0) 
            #log_progress_msg ""; 
            ;;
        esac
    done
    log_begin_msg "$NAME: All done (killed $_killCount procs)"; log_end_msg 0
    ;;



status)
    # Count how many processes we need
    PROCCOUNT=0
    for i in $SERVICES; do
        PROCCOUNT=`expr $PROCCOUNT + 1`
    done
    # Go through server PID files and count how many are running
    log_begin_msg "$NAME: Running processed:"
    _pidCount=0
    for server in $SERVICES; do
        isrunning $server
        case "$ISRUNNING" in
            1) 
                # This server is running
                _pidCount=`expr $_pidCount + 1`
                log_progress_msg "$server"
                ;;
            0) 
                ;;
        esac
    done
    log_begin_msg " ($_pidCount of $PROCCOUNT processes are running)"; log_end_msg 0
  
    # Check if running proc count matches requires proc count
    log_begin_msg "$NAME is"
    if [ $_pidCount -eq $PROCCOUNT ]; then
        log_progress_msg "running"; log_end_msg 0
        exit 0
    else
        log_progress_msg "NOT running"; log_end_msg 0
        exit 1
    fi
    ;;
restart)
    $0 stop
    $0 start
    ;;
*)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" >&2
    exit 1
    ;;
esac
exit 0
Personal tools
General
About This Wiki