3 # plc Manages all PLC services on this machine
7 # description: Manages all PLC services on this machine
12 PATH=/sbin:/bin:/usr/bin:/usr/sbin
14 # Source function library.
15 if [ -f /etc/init.d/functions ] ; then
16 . /etc/init.d/functions
19 # If success() or failure() are not defined
20 if ! type -type success >/dev/null || ! type -type failure >/dev/null ; then
31 # Source configuration
32 SERVICE=$(basename $0)
33 if [ ! -f /etc/sysconfig/$SERVICE ] ; then
36 if [ -f /etc/sysconfig/$SERVICE -a -z "${PLC_ROOT}${PLC_DATA}" ] ; then
37 . /etc/sysconfig/$SERVICE
40 # Total number of errors
43 # Count the exit status of the last command
46 ERRORS=$(($ERRORS+$?))
51 if cut -d' ' -f2 /proc/mounts | grep -q "$1" ; then
60 echo -n $"Mounting PLC: "
62 if ! mounted $PLC_ROOT ; then
63 if ! e2fsck -a $PLC_ROOT.img | logger -t "PLC" ; then
66 mount -o loop $PLC_ROOT.img $PLC_ROOT
69 if ! mounted $PLC_ROOT/data ; then
70 mount -t none -o bind,rw $PLC_DATA $PLC_ROOT/data
73 if ! mounted $PLC_ROOT/proc ; then
74 mount -t proc none $PLC_ROOT/proc
78 [ $ERRORS -eq 0 ] && success $"PLC unmount" || failure $"PLC unmount"
90 chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS start $*
96 echo -n $"Unmounting PLC: "
98 for dir in $PLC_ROOT/proc $PLC_ROOT/data $PLC_ROOT ; do
99 if mounted $dir ; then
105 [ $ERRORS -eq 0 ] && success $"PLC unmount" || failure $"PLC unmount"
111 if mounted $PLC_ROOT ; then
112 chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS stop $*
117 if [ -z "$1" ] ; then
124 for dir in $PLC_ROOT/proc $PLC_ROOT/data $PLC_ROOT ; do
125 if mounted $dir ; then
131 # safestop : tries to stop normally; if that fails, kills processes that are still using /plc
132 # needs the lsof rpm in the root context (should be a dependency of the myplc spec)
133 function check_command ()
136 found=$(type -p $command)
137 if [ -z "$found" ] ; then
138 echo "$COMMAND : requires command $command, was not found - exiting"
144 ### when process stil use /plc/root, we cannot umount it
147 [ -n "$DEBUG" ] && set -x
150 echo -n "Killing processes using $PLC_ROOT and $PLC_DATA: "
151 # initialize process list
152 former_process_list="unlikely"
154 # we ignore unknown uids for now, since we run in the chroot jail anyway
155 # not too sure about that though,
157 # get the list of processes - collapse and remove empty lines
158 process_list=$(lsof -t +D $PLC_ROOT +D $PLC_DATA)
159 if [ -z "$process_list" ] ; then
160 # we are done, let's bail out
161 success "$PLC_ROOT clear" ; echo ; return
163 if [ "$process_list" = "$former_process_list" ] ; then
164 # we are stuck, no progress since last time : exit on error
165 failure "$PLC_ROOT locked" ; echo ; return
167 # record for next loop
168 former_process_list="$process_list"
172 # check there are dead
173 for pid in $process_list ; do
174 ps -o pid $pid &> /dev/null
175 if [ "$?" = 0 ] ; then
176 [ -n "$DEBUG" ] && echo "$pid survived kill - forcing kill -9"
184 shift $(($OPTIND - 1))
202 chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS reload $*
205 mount|umount|mountstatus)
215 ### Checking : we might need to run kill
216 mounted=$(mountstatus_plc)
217 if [ -n "$mounted" ] ; then
218 echo "Umount failed : killing remaining processes and trying again"
227 echo "Usage: $0 {start|stop|restart|reload|mount|umount|mountstatus|kill|safestop}"