- explicitly add openssh requirement
[myplc.git] / host.init
1 #!/bin/bash
2 #
3 # plc   Manages all PLC services on this machine
4 #
5 # chkconfig: 2345 99 5
6 #
7 # description:  Manages all PLC services on this machine
8 #
9 # $Id: host.init,v 1.1.1.1 2006/03/27 17:36:46 mlhuang Exp $
10 #
11
12 PATH=/sbin:/bin:/usr/bin:/usr/sbin
13
14 # Source function library.
15 . /etc/init.d/functions
16
17 # Source configuration
18 if [ -f /etc/sysconfig/plc -a -z "${PLC_ROOT}${PLC_DATA}" ] ; then
19     . /etc/sysconfig/plc
20 fi
21
22 RETVAL=0
23
24 start ()
25 {
26     echo -n $"Mounting PLC: "
27
28     if ! cut -d' ' -f2 /proc/mounts | grep -q $PLC_ROOT ; then
29         if ! e2fsck -a $PLC_ROOT.img | logger -t "PLC" ; then
30             e2fsck $PLC_ROOT.img
31         fi
32         mount -o loop $PLC_ROOT.img $PLC_ROOT
33         RETVAL=$(($RETVAL+$?))
34     fi
35     if ! cut -d' ' -f2 /proc/mounts | grep -q $PLC_ROOT/data ; then
36         mount -t none -o bind,rw $PLC_DATA $PLC_ROOT/data
37         RETVAL=$(($RETVAL+$?))
38     fi
39     if ! cut -d' ' -f2 /proc/mounts | grep -q $PLC_ROOT/proc ; then
40         mount -t proc none $PLC_ROOT/proc
41         RETVAL=$(($RETVAL+$?))
42     fi
43
44     if [ $RETVAL -eq 0 ]; then
45         success $"PLC mount"
46     else
47         failure $"PLC mount"
48     fi
49     echo
50
51     chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS start
52     RETVAL=$?
53 }
54
55 stop ()
56 {
57     chroot $PLC_ROOT /sbin/service plc $PLC_OPTIONS stop
58
59     echo -n $"Unmounting PLC: "
60
61     umount $PLC_ROOT/proc
62     RETVAL=$(($RETVAL+$?))
63     umount $PLC_ROOT/data
64     RETVAL=$(($RETVAL+$?))
65     umount $PLC_ROOT
66     RETVAL=$(($RETVAL+$?))
67
68     if [ $RETVAL -eq 0 ]; then
69         success $"PLC unmount"
70     else
71         failure $"PLC unmount"  
72     fi
73     echo
74 }
75
76 case "$1" in
77     start|stop)
78         $1
79         ;;
80
81     restart)
82         stop
83         start
84         ;;
85
86     *)
87         echo "Usage: $0 {start|stop|restart}"
88         RETVAL=1
89         ;;
90 esac
91
92 exit $RETVAL