Difference between revisions of "Seon Core init script"

From Seon
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
For runlevel scripts, this script can be used as a basis for further needs. It works good in an SeonBox environment.
+
For runlevel scripts, this script can be used as a basis for further needs. It works good in an SeonBox environment. Actual versions of init-scripts can be found here: http://www.seon.de/downloads/
 
<pre>
 
<pre>
 
#! /bin/sh
 
#! /bin/sh
Line 9: Line 9:
 
# Default-Stop:      0 1 2 6
 
# Default-Stop:      0 1 2 6
 
# Short-Description: Seon
 
# Short-Description: Seon
# Description:      Start and stop Seon daemons
+
# Description:      Start and stop Seon daemons, update Seon
 
### END INIT INFO
 
### END INIT INFO
  
Line 21: Line 21:
 
. $Seon_CONFIG
 
. $Seon_CONFIG
  
# retrieve backup directory
+
# retrieve directories and settings
 
Seon_BINDIR=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='bin_directory'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
 
Seon_BINDIR=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='bin_directory'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
 
Seon_ENTERPRISE=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='seon_enterprise'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
 
Seon_ENTERPRISE=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='seon_enterprise'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
 +
Seon_WEBINTERFACE=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='webinterface_path'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
 +
LCDECHO=/usr/local/bin/lcdecho
  
 
# Check for missing binaries (stale symlinks should not happen)
 
# Check for missing binaries (stale symlinks should not happen)
Line 29: Line 31:
 
SeonRD_BIN=$Seon_BINDIR/seonrd
 
SeonRD_BIN=$Seon_BINDIR/seonrd
 
test -x $SeonRD_BIN || { echo "$SeonRD_BIN not installed";  
 
test -x $SeonRD_BIN || { echo "$SeonRD_BIN not installed";  
        if [ "$1" = "stop" ]; then exit 0;
+
if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }
+
else exit 5; fi; }
  
 
SeonSQD_BIN=$Seon_BINDIR/seonsqd
 
SeonSQD_BIN=$Seon_BINDIR/seonsqd
Line 44: Line 46:
 
if [ $Seon_ENTERPRISE -gt 0 ]
 
if [ $Seon_ENTERPRISE -gt 0 ]
 
then
 
then
        SeonCLIENTD_BIN=$Seon_BINDIR/seonclientd
+
SeonCLIENTD_BIN=$Seon_BINDIR/seonclientd
        test -x $SeonCLIENTD_BIN || { echo "$SeonCLIENTD_BIN not installed";
+
test -x $SeonCLIENTD_BIN || { echo "$SeonCLIENTD_BIN not installed";
                if [ "$1" = "stop" ]; then exit 0;
+
        if [ "$1" = "stop" ]; then exit 0;
                else exit 5; fi; }
+
        else exit 5; fi; }
 
fi
 
fi
 +
 +
SeonPOLL_BIN=$Seon_BINDIR/seonpoll
 +
test -x $SeonPOLL_BIN || { echo "$SeonPOLL_BIN not installed";
 +
        if [ "$1" = "stop" ]; then exit 0;
 +
        else exit 5; fi; }
  
 
case "$1" in
 
case "$1" in
 
     start)
 
     start)
        echo -n "Starting Seon "
+
    # pre-check lockfile
        echo -n "seonrd... "
+
    if [ -d $Seon_WEBINTERFACE ]
        $SeonRD_BIN
+
    then
        echo -n "seonsqd... "
+
      if [ -e ${Seon_WEBINTERFACE}/blank_install ]
        $SeonSQD_BIN
+
      then
        echo -n "seondebugd... "
+
         # try to recover installation
         $SeonDEBUGD_BIN
+
         if [ -e /sd_card/seon.*.sql.gz ]
         if [ $Seon_ENTERPRISE -gt 0 ]
 
 
         then
 
         then
                echo -n "seonclientd... "
+
          # backupfile exists, restore complete system
                $SeonCLIENTD_BIN
+
          /opt/seon/scripts/systemrestore_from_sd.sh && rm -f ${Seon_WEBINTERFACE}/blank_install
 +
        else
 +
          echo "not starting Seon: blank installation, please configure Seon"
 +
          exit
 
         fi
 
         fi
        echo "OK"
+
      fi
        ;;
+
    fi
 +
 
 +
echo -n "Starting Seon "
 +
echo -n "seonrd... "
 +
$SeonRD_BIN
 +
echo -n "seonsqd... "
 +
$SeonSQD_BIN
 +
echo -n "seondebugd... "
 +
$SeonDEBUGD_BIN
 +
if [ $Seon_ENTERPRISE -gt 0 ]
 +
then
 +
echo -n "seonclientd... "
 +
$SeonCLIENTD_BIN
 +
fi
 +
echo "OK"
 +
if [ -x $LCDECHO ]
 +
then
 +
$LCDECHO -a "Seon started" -t 10
 +
fi
 +
;;
 
     stop)
 
     stop)
        echo -n "Shutting down Seon "
+
echo -n "Shutting down Seon "
        echo -n "seonrd... "
+
echo -n "seonrd... "
        killall seonrd 1> /dev/null 2>1
+
killall seonrd >/dev/null 2>&1
        echo -n "seonsqd... "
+
echo -n "seonsqd... "
        killall seonsqd 1> /dev/null 2>1
+
killall seonsqd >/dev/null 2>&1
        echo -n "seondebugd... "
+
echo -n "seondebugd... "
        killall seondebugd 1> /dev/null 2>1
+
killall seondebugd >/dev/null 2>&1
        if [ $Seon_ENTERPRISE -gt 0 ]
+
if [ $Seon_ENTERPRISE -gt 0 ]
        then  
+
then  
                echo -n "seonclientd... "
+
echo -n "seonclientd... "
                killall seonclientd 1> /dev/null 2>1
+
killall seonclientd >/dev/null 2>&1
        fi
+
fi
        echo OK
+
echo OK
         ;;
+
         if [ -x $LCDECHO ]
 +
        then
 +
        $LCDECHO -a "Seon stopped" -t 10
 +
fi
 +
        sleep 10
 +
;;
 
     status)
 
     status)
        echo -n "Checking for service Seon "
+
echo -n "Checking for service Seon "
        pidof seonrd > /dev/null
+
pidof seonrd >/dev/null 2>&1 
        if [ $? -ne 0 ]
+
if [ $? -ne 0 ]
        then
+
then
          echo -n "... seonrd is not running"
+
  echo -n "... seonrd is not running"
        else
+
else
          echo -n "... seonrd OK "
+
  echo -n "... seonrd OK "
        fi  
+
fi  
        pidof seonsqd > /dev/null
+
pidof seonsqd >/dev/null 2>&1 
        if [ $? -ne 0 ]
+
if [ $? -ne 0 ]
 
         then
 
         then
          echo -n "... seonsqd is not running"
+
  echo -n "... seonsqd is not running"
        else
+
else
          echo -n "... seonsqd OK "
+
  echo -n "... seonsqd OK "
 
         fi
 
         fi
        pidof seondebugd > /dev/null
+
pidof seondebugd > /dev/null 2>&1
        if [ $? -ne 0 ]
+
if [ $? -ne 0 ]
 
         then
 
         then
          echo "... seondebugd is not running"
+
  echo -n "... seondebugd is not running"
        else
+
else
          echo -n "... seondebugd OK "
+
  echo -n "... seondebugd OK "
 
         fi
 
         fi
        if [ $Seon_ENTERPRISE -gt 0 ]
+
if [ $Seon_ENTERPRISE -gt 0 ]
 +
then
 +
pidof seonclientd >/dev/null 2>&1 
 +
        if [ $? -ne 0 ]
 +
        then
 +
        echo "... seonclientd is not running"
 +
      else
 +
        echo "... seonclientd OK "
 +
        fi
 +
else
 +
echo ""
 +
fi
 +
;;
 +
    update)
 +
echo -n "Initiating Seon update... "
 +
        $SeonPOLL_BIN Seon-Update
 +
if [ -x $LCDECHO ]
 
         then
 
         then
                pidof seonclientd > /dev/null
+
$LCDECHO -a "Seon updating" -t 10
                if [ $? -ne 0 ]
+
fi
                then
+
echo "OK"
                  echo "... seonclientd is not running"
+
;;
                else
 
                  echo "... seonclientd OK "
 
                fi
 
        else
 
                echo ""
 
        fi
 
        ;;
 
 
     *)
 
     *)
        echo "Usage: $0 {start|stop|status}"
+
echo "Usage: $0 {start|stop|status|update}"
        exit 1
+
exit 1
        ;;
+
;;
 
esac
 
esac
 
# rc_exit
 
# rc_exit
 
</pre>
 
</pre>

Latest revision as of 14:59, 13 December 2011

For runlevel scripts, this script can be used as a basis for further needs. It works good in an SeonBox environment. Actual versions of init-scripts can be found here: http://www.seon.de/downloads/

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

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

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

# retrieve directories and settings
Seon_BINDIR=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='bin_directory'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
Seon_ENTERPRISE=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='seon_enterprise'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
Seon_WEBINTERFACE=`echo "SELECT value FROM ${TABLEPREFIX}configuration WHERE name='webinterface_path'" | $MYSQLCLIENT --silent --user=$DB_USER --password=$DB_PASS --host=$DB_HOST $DB_NAME`
LCDECHO=/usr/local/bin/lcdecho

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

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

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

if [ $Seon_ENTERPRISE -gt 0 ]
then
	SeonCLIENTD_BIN=$Seon_BINDIR/seonclientd
	test -x $SeonCLIENTD_BIN || { echo "$SeonCLIENTD_BIN not installed";
        	if [ "$1" = "stop" ]; then exit 0;
        	else exit 5; fi; }
fi

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

case "$1" in
    start)
    # pre-check lockfile
    if [ -d $Seon_WEBINTERFACE ]
    then
      if [ -e ${Seon_WEBINTERFACE}/blank_install ]
      then
        # try to recover installation
        if [ -e /sd_card/seon.*.sql.gz ]
        then
          # backupfile exists, restore complete system
          /opt/seon/scripts/systemrestore_from_sd.sh && rm -f ${Seon_WEBINTERFACE}/blank_install
        else
          echo "not starting Seon: blank installation, please configure Seon"
          exit
        fi
      fi
    fi

	echo -n "Starting Seon "
 	echo -n "seonrd... "
	$SeonRD_BIN
	echo -n "seonsqd... "
	$SeonSQD_BIN
	echo -n "seondebugd... "
	$SeonDEBUGD_BIN
	if [ $Seon_ENTERPRISE -gt 0 ]
	then
		echo -n "seonclientd... "
		$SeonCLIENTD_BIN
	fi
	echo "OK"
	if [ -x $LCDECHO ]
	then
		$LCDECHO -a "Seon started" -t 10
	fi
	;;
    stop)
	echo -n "Shutting down Seon "
	echo -n "seonrd... "
	killall seonrd >/dev/null 2>&1  
	echo -n "seonsqd... "
	killall seonsqd >/dev/null 2>&1  
	echo -n "seondebugd... "
	killall seondebugd >/dev/null 2>&1  
	if [ $Seon_ENTERPRISE -gt 0 ]
	then 
		echo -n "seonclientd... "
		killall seonclientd >/dev/null 2>&1  
	fi
	echo OK
        if [ -x $LCDECHO ]
        then
        	$LCDECHO -a "Seon stopped" -t 10
	fi
        sleep 10
	;;
    status)
	echo -n "Checking for service Seon "
	pidof seonrd >/dev/null 2>&1  
	if [ $? -ne 0 ]
	then
	  echo -n "... seonrd is not running"
	else
	  echo -n "... seonrd OK "
	fi 
	pidof seonsqd >/dev/null 2>&1  
	if [ $? -ne 0 ]
        then
	  echo -n "... seonsqd is not running"
	else
	  echo -n "... seonsqd OK "
        fi
	pidof seondebugd > /dev/null 2>&1 
	if [ $? -ne 0 ]
        then
	  echo -n "... seondebugd is not running"
	else
	  echo -n "... seondebugd OK "
        fi
	if [ $Seon_ENTERPRISE -gt 0 ]
	then
		pidof seonclientd >/dev/null 2>&1  
        	if [ $? -ne 0 ]
        	then
       		   echo "... seonclientd is not running"
       		else
       		   echo "... seonclientd OK "
        	fi
	else
		echo ""
	fi
	;;
    update)
	echo -n "Initiating Seon update... "
        $SeonPOLL_BIN Seon-Update
	if [ -x $LCDECHO ]
        then
		$LCDECHO -a "Seon updating" -t 10
	fi
	echo "OK"
	;;
    *)
	echo "Usage: $0 {start|stop|status|update}"
	exit 1
	;;
esac
# rc_exit