Seon Core init script

From Seon
Jump to: navigation, search

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