Release.
[safe/jmp/vzgot] / support / redhat_init.sh
1 #!/bin/sh
2 #
3 # vzgot         This shell script takes care of starting and stopping
4 #               vzgot container with the "ON" status
5 #
6 # description:  Scan vzgot vdir directory to find out about container
7 #               and start them if requested.
8 #
9 # chkconfig: - 98 2
10 #   description: Startup/shutdown vzgot containers
11 ### BEGIN INIT INFO
12 # Provides: vzgot
13 # Required-Start: network
14 # Required-Stop:
15 # Default-Start: 
16 # Default-Stop: 0 1 6
17 # Short-Description: starting container
18 ### END INIT INFO
19
20
21 #basic function
22 [ -f  /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
23
24 if [ -f /etc/vzgot/vzgot_config ] ; then
25   . /etc/vzgot/vzgot_config
26   fi
27
28 #------------------------------------------------------------------
29 vzgotstart()
30
31 {
32 echo -n "Vzgot starting" && success || failure
33 echo
34 count=0
35 for cont in `ls $VZLIB/vzdir` 
36   do
37   if ! [ -f $VZLIB/vzdir/status ] ; then
38     . $VZLIB/vzdir/$cont/status
39
40     case "$BOOT" in 
41       "ON"      )
42         if ! [ -f $VZLIB/vzdir/$cont/first.pid ] ; then
43           BOOTLOG=$VZLIB/vzdir/$cont/bootlog
44           date > $BOOTLOG
45           echo -n "Booting container $cont"
46           vzgot boot $cont && success || failure
47           echo
48           count=`expr $count + 1`
49           fi
50         ;;
51       "*"       )
52         ;;
53       esac
54     fi
55   done
56 echo -n "vzgot: $count container started" && success || failure
57 echo 
58 }
59
60 vzgotstop()
61
62 {
63 echo -n "Vzgot stopping" && success || failure
64 echo
65 for cont in `ls $VZLIB/vzdir` 
66   do
67   if [ -f $VZLIB/vzdir/$cont/first.pid ] ; then
68     echo -n "Halting container $cont"
69     vzgot shutdown $cont && success || failure
70     echo
71     while [ -f /$VZLIB/vzdir/$cont/first.pid ] ; do
72       sleep 1
73       done
74     fi
75   done
76 echo -n "vzgot: all container now down" && success || failure
77 echo
78 }
79
80 #------------------------------------------------------------------
81 case "$1" in
82   start)
83         # Start daemons.
84         touch /var/lock/subsys/vzgot
85         vzgotstart
86         
87         ;;
88
89   stop)
90         # Stopping daemons.
91         vzgotstop
92         rm -f /var/lock/subsys/vzgot
93         ;;
94
95   restart)
96         $0 stop
97         $0 start
98         ;;
99
100   reload)
101         echo "Nothing to do"
102         ;;
103
104   status)
105         status $PROG
106         ;;
107   *)
108         echo "Usage: regulus {start|stop|restart|status}"
109         exit 1
110 esac
111
112 exit 0
113