OS4X Core init script

From OS4X
Revision as of 20:07, 11 April 2007 by Admin (talk | contribs) (New page: For runlevel scripts, this script can be used as a basis for further needs. It works good in an OS4XBox environment. <pre> #! /bin/sh ### BEGIN INIT INFO # Provides: OS4X # Requir...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

For runlevel scripts, this script can be used as a basis for further needs. It works good in an OS4XBox environment.

#! /bin/sh
### BEGIN INIT INFO
# Provides:          OS4X
# Required-Start:    mysql
# Should-Start: mysql
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: OS4X
# Description:       Start and stop OS4X daemons
### END INIT INFO

# Check for existence of needed config file and read it
OS4X_CONFIG=/etc/os4x.conf
test -r $OS4X_CONFIG || { echo "$OS4X_CONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }  

# first, source the config file for database parameters
. $OS4X_CONFIG

# retrieve backup directory
OS4X_BINDIR=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='bin_directory'" | mysql --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
OS4XRD_BIN=$OS4X_BINDIR/os4xrd
test -x $OS4XRD_BIN || { echo "$OS4XRD_BIN not installed"; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

OS4XSQD_BIN=$OS4X_BINDIR/os4xsqd
test -x $OS4XSQD_BIN || { echo "$OS4XSQD_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }  

OS4XDEBUGD_BIN=$OS4X_BINDIR/os4xdebugd
test -x $OS4XDEBUGD_BIN || { echo "$OS4XDEBUGD_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }  

OS4XCLIENTD_BIN=$OS4X_BINDIR/os4xclientd
test -x $OS4XCLIENTD_BIN || { echo "$OS4XCLIENTD_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

case "$1" in
    start)
        echo -n "Starting OS4X "
        echo -n "os4xrd... "
        $OS4XRD_BIN
        echo -n "os4xsqd... "
        $OS4XSQD_BIN
        echo -n "os4xdebugd... "
        $OS4XDEBUGD_BIN
        echo -n "os4xclientd... "
        $OS4XCLIENTD_BIN
        echo "OK"
        ;;
    stop)
        echo -n "Shutting down OS4X "
        echo -n "os4xrd... "
        killall os4xrd 1> /dev/null 2>1
        echo -n "os4xsqd... "
        killall os4xsqd 1> /dev/null 2>1
        echo -n "os4xdebugd... "
        killall os4xdebugd 1> /dev/null 2>1
        echo -n "os4xclientd... "
        killall os4xclientd 1> /dev/null 2>1
        echo OK
        ;;
    status)
        echo -n "Checking for service OS4X "
        pidof os4xrd > /dev/null
        if [ $? -ne 0 ]
        then
          echo -n "... os4xrd is not running"
        else
          echo -n "... os4xrd OK "
        fi 
        pidof os4xsqd > /dev/null
        if [ $? -ne 0 ]
        then
          echo -n "... os4xsqd is not running"
        else
          echo -n "... os4xsqd OK "
        fi
        pidof os4xdebugd > /dev/null
        if [ $? -ne 0 ]
        then
          echo "... os4xdebugd is not running"
        else
          echo -n "... os4xdebugd OK "
        fi
        pidof os4xclientd > /dev/null
        if [ $? -ne 0 ]
        then
          echo "... os4xdebugd is not running"
        else
          echo "... os4xdebugd OK "
        fi

        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
        ;;
esac
# rc_exit