X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=host.init;h=f207e008a525ab98501024070e0b4c4dafd31e21;hb=73ea36ee50210d681c30ade8245b03d2ef67b22b;hp=5c22f9ce88e2c3181088e8aaced5887e265c2b8a;hpb=8829238904f8adc45d3412ae8d3af8329dca2e3e;p=myplc.git diff --git a/host.init b/host.init index 5c22f9c..f207e00 100755 --- a/host.init +++ b/host.init @@ -6,17 +6,35 @@ # # description: Manages all PLC services on this machine # -# $Id: host.init,v 1.3 2006/04/07 17:12:52 mlhuang Exp $ +# $Id: host.init,v 1.8 2006/07/06 17:43:52 mlhuang Exp $ # PATH=/sbin:/bin:/usr/bin:/usr/sbin # Source function library. -. /etc/init.d/functions +if [ -f /etc/init.d/functions ] ; then + . /etc/init.d/functions +fi + +# If success() or failure() are not defined +if ! type -type success >/dev/null || ! type -type failure >/dev/null ; then + success() { + echo -ne "[ OK ]\r" + return 0 + } + failure() { + echo -ne "[FAILED]\r" + return 1 + } +fi # Source configuration -if [ -f /etc/sysconfig/plc -a -z "${PLC_ROOT}${PLC_DATA}" ] ; then - . /etc/sysconfig/plc +SERVICE=$(basename $0) +if [ ! -f /etc/sysconfig/$SERVICE ] ; then + SERVICE=plc +fi +if [ -f /etc/sysconfig/$SERVICE -a -z "${PLC_ROOT}${PLC_DATA}" ] ; then + . /etc/sysconfig/$SERVICE fi # Total number of errors @@ -37,7 +55,7 @@ mounted () fi } -start () +mount_plc () { echo -n $"Mounting PLC: " @@ -60,17 +78,21 @@ start () [ $ERRORS -eq 0 ] && success $"PLC unmount" || failure $"PLC unmount" echo - chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS start $* - check } -stop () +start () { - if mounted $PLC_ROOT ; then - chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS stop $* - check + # Starting everything + if [ -z "$1" ] ; then + mount_plc fi + chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS start $* + check +} + +umount_plc () +{ echo -n $"Unmounting PLC: " for dir in $PLC_ROOT/proc $PLC_ROOT/data $PLC_ROOT ; do @@ -84,6 +106,28 @@ stop () echo } +stop () +{ + if mounted $PLC_ROOT ; then + chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS stop $* + check + fi + + # Stopped everything + if [ -z "$1" ] ; then + umount_plc + fi +} + +mountstatus_plc () +{ + for dir in $PLC_ROOT/proc $PLC_ROOT/data $PLC_ROOT ; do + if mounted $dir ; then + echo $dir + fi + done +} + # Get command shift $(($OPTIND - 1)) command=$1 @@ -101,8 +145,16 @@ case "$command" in start $* ;; + reload) + chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS reload $* + ;; + + mount|umount|mountstatus) + ${command}_plc $* + ;; + *) - echo "Usage: $0 {start|stop|restart}" + echo "Usage: $0 {start|stop|restart|reload|mount|umount|mountstatus}" RETVAL=1 ;; esac