3 # plc Manages all PLC services on this machine
7 # description: Manages all PLC services on this machine
9 # $Id: guest.init,v 1.20 2006/08/08 23:19:52 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
38 # Regenerate the main configuration file from default values
39 # overlaid with site-specific and current values.
41 /etc/planetlab/default_config.xml
42 /etc/planetlab/configs/*.xml
43 /etc/planetlab/plc_config.xml
45 for file in "${files[@]}" ; do
46 if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ] ; then
47 tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
48 plc-config --xml "${files[@]}" >$tmp
49 if [ $? -eq 0 ] ; then
50 mv $tmp /etc/planetlab/plc_config.xml
51 chmod 644 /etc/planetlab/plc_config.xml
53 echo "PLC: Warning: Invalid configuration file(s) detected"
60 # Convert configuration to various formats
61 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
62 plc-config --shell >/etc/planetlab/plc_config
64 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
65 mkdir -p /etc/planetlab/php
66 plc-config --php >/etc/planetlab/php/plc_config.php
72 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
74 echo " -h This message"
77 echo " start Start all PLC subsystems"
78 echo " stop Stop all PLC subsystems"
79 echo " reload Regenerate configuration files"
80 echo " restart Restart all PLC subsystems"
83 for step in "${steps[@]}" ; do
84 if [ -x /etc/plc.d/$step ] ; then
85 echo " $(basename $step)"
92 while getopts "vh" opt ; do
103 # Redirect stdout and stderr of each step to /var/log/boot.log
104 if [ $verbose -eq 0 ] ; then
105 touch /var/log/boot.log
106 chmod 600 /var/log/boot.log
107 exec 1>>/var/log/boot.log
108 exec 2>>/var/log/boot.log
112 shift $(($OPTIND - 1))
113 if [ -z "$1" ] ; then
120 if [ -z "$1" ] ; then
121 # Start or stop everything. Regenerate configuration first.
124 # Start or stop a particular step
133 for step in "${steps[@]}" ; do
134 if [ -x /etc/plc.d/$step ] ; then
135 /etc/plc.d/$step start
136 # Steps may alter the configuration, may need to regenerate
139 echo "PLC: $step: unrecognized step" >&4
147 for i in $(seq 1 $nsteps) ; do
148 step=${steps[$(($nsteps - $i))]}
149 if [ -x /etc/plc.d/$step ] ; then
150 /etc/plc.d/$step stop
151 # Steps may alter the configuration, may need to regenerate
154 echo "PLC: $step: unrecognized step" >&4