Difference between revisions of "OS4X Core init script"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
| − | For runlevel scripts, this script can be used as a basis for further needs. It works good in an OS4XBox environment. Actual versions of init-scripts can be found here: http://www.os4x.com/downloads | + | For runlevel scripts, this script can be used as a basis for further needs. It works good in an OS4XBox environment. Actual versions of init-scripts can be found here: http://www.os4x.com/downloads/ |
<pre> | <pre> | ||
#! /bin/sh | #! /bin/sh | ||
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 OS4XBox environment. Actual versions of init-scripts can be found here: http://www.os4x.com/downloads/
#! /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, update OS4X
### 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 directories and settings
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`
OS4X_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
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
OS4XPOLL_BIN=$OS4X_BINDIR/os4xpoll
test -x $OS4XPOLL_BIN || { echo "$OS4XPOLL_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
case "$1" in
start)
# pre-check lockfile
if [ -d $OS4X_WEBINTERFACE ]
then
if [ -e ${OS4X_WEBINTERFACE}/blank_install ]
then
# try to recover installation
if [ -e /sd_card/os4x.*.sql.gz ]
then
# backupfile exists, restore complete system
/opt/os4x/scripts/systemrestore_from_sd.sh && rm -f ${OS4X_WEBINTERFACE}/blank_install
else
echo "not starting OS4X: blank installation, please configure OS4X"
exit
fi
fi
fi
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"
if [ -x $LCDECHO ]
then
$LCDECHO -a "OS4X started" -t 10
fi
;;
stop)
echo -n "Shutting down OS4X "
echo -n "os4xrd... "
killall os4xrd >/dev/null 2>&1
echo -n "os4xsqd... "
killall os4xsqd >/dev/null 2>&1
echo -n "os4xdebugd... "
killall os4xdebugd >/dev/null 2>&1
if [ $OS4X_ENTERPRISE -gt 0 ]
then
echo -n "os4xclientd... "
killall os4xclientd >/dev/null 2>&1
fi
echo OK
if [ -x $LCDECHO ]
then
$LCDECHO -a "OS4X stopped" -t 10
fi
sleep 10
;;
status)
echo -n "Checking for service OS4X "
pidof os4xrd >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo -n "... os4xrd is not running"
else
echo -n "... os4xrd OK "
fi
pidof os4xsqd >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo -n "... os4xsqd is not running"
else
echo -n "... os4xsqd OK "
fi
pidof os4xdebugd > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo -n "... os4xdebugd is not running"
else
echo -n "... os4xdebugd OK "
fi
if [ $OS4X_ENTERPRISE -gt 0 ]
then
pidof os4xclientd >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "... os4xclientd is not running"
else
echo "... os4xclientd OK "
fi
else
echo ""
fi
;;
update)
echo -n "Initiating OS4X update... "
$OS4XPOLL_BIN OS4X-Update
if [ -x $LCDECHO ]
then
$LCDECHO -a "OS4X updating" -t 10
fi
echo "OK"
;;
*)
echo "Usage: $0 {start|stop|status|update}"
exit 1
;;
esac
# rc_exit