3 # plc Manages all PLC services on this machine
7 # description: Manages all PLC services on this machine
9 # $Id: guest.init,v 1.18 2006/06/23 21:48:41 mlhuang Exp $
12 # Source function library and configuration
13 . /etc/plc.d/functions
18 # All steps should be idempotent. This means that you should be able
19 # to run them multiple times without depending on anything previously
20 # being run. The idea is that when the configuration changes, "service
21 # plc restart" is called, all dependencies are fixed up, and
22 # everything just works.
24 for step in /etc/plc.d/* ; do
25 if [ -f $step -a -x $step ] ; then
26 priority=$(sed -ne 's/# priority: \(.*\)/\1/p' $step)
27 echo $priority $(basename $step)
29 done | sort -n | cut -d' ' -f2
33 # Regenerate configuration files
36 # Regenerate the main configuration file from default values
37 # overlaid with site-specific and current values.
39 /etc/planetlab/default_config.xml
40 /etc/planetlab/configs/*
41 /etc/planetlab/plc_config.xml
43 for file in "${files[@]}" ; do
44 if [ $file -nt /etc/planetlab/plc_config.xml ] ; then
45 tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
46 plc-config --xml "${files[@]}" >$tmp
47 if [ $? -eq 0 ] ; then
48 mv $tmp /etc/planetlab/plc_config.xml
49 chmod 644 /etc/planetlab/plc_config.xml
51 echo "PLC: Warning: Invalid configuration file(s) detected"
58 # Convert configuration to various formats
59 if [ /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
60 plc-config --shell >/etc/planetlab/plc_config
62 if [ /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
63 mkdir -p /etc/planetlab/php
64 plc-config --php >/etc/planetlab/php/plc_config.php
70 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
72 echo " -h This message"
75 echo " start Start all PLC subsystems"
76 echo " stop Stop all PLC subsystems"
77 echo " reload Regenerate configuration files"
78 echo " restart Restart all PLC subsystems"
81 for step in "${steps[@]}" ; do
82 if [ -x /etc/plc.d/$step ] ; then
83 echo " $(basename $step)"
90 while getopts "vh" opt ; do
101 # Redirect stdout and stderr of each step to /var/log/boot.log
102 if [ $verbose -eq 0 ] ; then
103 touch /var/log/boot.log
104 chmod 600 /var/log/boot.log
105 exec 1>>/var/log/boot.log
106 exec 2>>/var/log/boot.log
110 shift $(($OPTIND - 1))
111 if [ -z "$1" ] ; then
118 if [ -z "$1" ] ; then
119 # Start or stop everything. Regenerate configuration first.
122 # Start or stop a particular step
131 for step in "${steps[@]}" ; do
132 if [ -x /etc/plc.d/$step ] ; then
133 /etc/plc.d/$step start
134 # Steps may alter the configuration, may need to regenerate
137 echo "PLC: $step: unrecognized step" >&4
145 for i in $(seq 1 $nsteps) ; do
146 step=${steps[$(($nsteps - $i))]}
147 if [ -x /etc/plc.d/$step ] ; then
148 /etc/plc.d/$step stop
149 # Steps may alter the configuration, may need to regenerate
152 echo "PLC: $step: unrecognized step" >&4