Difference between revisions of "OS4X Core init script"

From OS4X
Jump to navigation Jump to search
(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...)
 
Line 22: Line 22:
  
 
# retrieve backup directory
 
# 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`
+
OS4X_BINDIR=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='bin_directory'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
 +
OS4X_ENTERPRISE=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='os4x_enterprise'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
  
 
# Check for missing binaries (stale symlinks should not happen)
 
# Check for missing binaries (stale symlinks should not happen)
Line 41: Line 42:
 
         else exit 5; fi; }   
 
         else exit 5; fi; }   
  
OS4XCLIENTD_BIN=$OS4X_BINDIR/os4xclientd
+
if [ $OS4X_ENTERPRISE -gt 0 ]
test -x $OS4XCLIENTD_BIN || { echo "$OS4XCLIENTD_BIN not installed";
+
then
        if [ "$1" = "stop" ]; then exit 0;
+
        OS4XCLIENTD_BIN=$OS4X_BINDIR/os4xclientd
        else exit 5; fi; }
+
        test -x $OS4XCLIENTD_BIN || { echo "$OS4XCLIENTD_BIN not installed";
 +
                if [ "$1" = "stop" ]; then exit 0;
 +
                else exit 5; fi; }
 +
fi
  
 
case "$1" in
 
case "$1" in
Line 55: Line 59:
 
         echo -n "os4xdebugd... "
 
         echo -n "os4xdebugd... "
 
         $OS4XDEBUGD_BIN
 
         $OS4XDEBUGD_BIN
         echo -n "os4xclientd... "
+
         if [ $OS4X_ENTERPRISE -gt 0 ]
        $OS4XCLIENTD_BIN
+
        then
 +
                echo -n "os4xclientd... "
 +
                $OS4XCLIENTD_BIN
 +
        fi
 
         echo "OK"
 
         echo "OK"
 
         ;;
 
         ;;
Line 67: Line 74:
 
         echo -n "os4xdebugd... "
 
         echo -n "os4xdebugd... "
 
         killall os4xdebugd 1> /dev/null 2>1
 
         killall os4xdebugd 1> /dev/null 2>1
         echo -n "os4xclientd... "
+
         if [ $OS4X_ENTERPRISE -gt 0 ]
        killall os4xclientd 1> /dev/null 2>1
+
        then
 +
                echo -n "os4xclientd... "
 +
                killall os4xclientd 1> /dev/null 2>1
 +
        fi
 
         echo OK
 
         echo OK
 
         ;;
 
         ;;
Line 94: Line 104:
 
           echo -n "... os4xdebugd OK "
 
           echo -n "... os4xdebugd OK "
 
         fi
 
         fi
        pidof os4xclientd > /dev/null
+
         if [ $OS4X_ENTERPRISE -gt 0 ]
         if [ $? -ne 0 ]
 
 
         then
 
         then
          echo "... os4xdebugd is not running"
+
                pidof os4xclientd > /dev/null
 +
                if [ $? -ne 0 ]
 +
                then
 +
                  echo "... os4xclientd is not running"
 +
                else
 +
                  echo "... os4xclientd OK "
 +
                fi
 
         else
 
         else
          echo "... os4xdebugd OK "
+
                echo ""
 
         fi
 
         fi
 
 
         ;;
 
         ;;
 
     *)
 
     *)

Revision as of 20:16, 11 April 2007

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'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
OS4X_ENTERPRISE=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='os4x_enterprise'" | $MYSQLCLIENT --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; }  

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

case "$1" in
    start)
        echo -n "Starting OS4X "
        echo -n "os4xrd... "
        $OS4XRD_BIN
        echo -n "os4xsqd... "
        $OS4XSQD_BIN
        echo -n "os4xdebugd... "
        $OS4XDEBUGD_BIN
        if [ $OS4X_ENTERPRISE -gt 0 ]
        then
                echo -n "os4xclientd... "
                $OS4XCLIENTD_BIN
        fi
        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
        if [ $OS4X_ENTERPRISE -gt 0 ]
        then 
                echo -n "os4xclientd... "
                killall os4xclientd 1> /dev/null 2>1
        fi
        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
        if [ $OS4X_ENTERPRISE -gt 0 ]
        then
                pidof os4xclientd > /dev/null
                if [ $? -ne 0 ]
                then
                   echo "... os4xclientd is not running"
                else
                   echo "... os4xclientd OK "
                fi
        else
                echo ""
        fi
        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
        ;;
esac
# rc_exit