3 # plc Manages all PLC services on this machine
7 # description: Manages all PLC services on this machine
13 # Source function library and configuration
14 . /etc/plc.d/functions
19 # All steps should be idempotent. This means that you should be able
20 # to run them multiple times without depending on anything previously
21 # being run. The idea is that when the configuration changes, "service
22 # plc restart" is called, all dependencies are fixed up, and
23 # everything just works.
26 # we want the resulting myplc to be able to easily skip
27 # some steps. e.g. the packages step takes ages if you install
28 # all rpms under the repository.
29 # We skip steps whose name contains a dot (.) or a tilde (~)
30 # this way the operations would just rename a step name e.g.
32 # mv packages packages.hide
34 # The drawback is, this stuff does not survive an rpm update
35 # but that's maybe a good thing, that all is done at first start
39 for step in /etc/plc.d/* ; do
40 stepname=$(basename $step)
41 plainstepname=$(echo $stepname | sed -e 's,\.,,' -e 's,~,,')
42 if [ -f $step -a -x $step -a "$stepname" = "$plainstepname" ] ; then
43 priority=$(sed -ne 's/# priority: \(.*\)/\1/p' $step)
44 echo $priority $stepname
46 done | sort -n | cut -d' ' -f2
50 # Regenerate configuration files
55 # Regenerate the main configuration file from default values
56 # overlaid with site-specific and current values.
57 # Thierry -- 2007-07-05 : values in plc_config.xml are *not* taken into account here
59 /etc/planetlab/default_config.xml
60 /etc/planetlab/configs/site.xml
62 for file in "${files[@]}" ; do
63 if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ] ; then
64 tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
65 plc-config --xml "${files[@]}" >$tmp
66 if [ $? -eq 0 ] ; then
67 mv $tmp /etc/planetlab/plc_config.xml
68 chmod 444 /etc/planetlab/plc_config.xml
70 echo "PLC: Warning: Invalid configuration file(s) detected"
77 # Convert configuration to various formats
78 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
79 plc-config --shell >/etc/planetlab/plc_config
81 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ] ; then
82 plc-config --python >/etc/planetlab/plc_config.py
84 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
85 mkdir -p /etc/planetlab/php
86 plc-config --php >/etc/planetlab/php/plc_config.php
92 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
94 echo " -h This message"
97 echo " start Start all PLC subsystems"
98 echo " stop Stop all PLC subsystems"
99 echo " reload Regenerate configuration files"
100 echo " restart Restart all PLC subsystems"
101 echo " checkpoint filename : Checkpoint the current state of MyPLC to filename"
102 echo " restore filename : Restore MyPLC state from filename"
103 echo " steps Displays ordered list of subsystems"
106 for step in "${steps[@]}" ; do
107 if [ -x /etc/plc.d/$step ] ; then
108 echo " $(basename $step)"
115 while getopts "vh" opt ; do
126 # Redirect stdout and stderr of each step to /var/log/boot.log
127 if [ $verbose -eq 0 ] ; then
128 touch /var/log/boot.log
129 chmod 600 /var/log/boot.log
130 exec 1>>/var/log/boot.log
131 exec 2>>/var/log/boot.log
135 shift $(($OPTIND - 1))
136 if [ -z "$1" ] ; then
143 if [ -z "$1" ] ; then
144 # Start or stop everything. Regenerate configuration first.
147 # Start or stop a particular step
156 for step in "${steps[@]}" ; do
157 if [ -x /etc/plc.d/$step ] ; then
158 /etc/plc.d/$step start
159 # Steps may alter the configuration, may need to regenerate
162 echo "PLC: $step: unrecognized step" >&4
170 for i in $(seq 1 $nsteps) ; do
171 step=${steps[$(($nsteps - $i))]}
172 if [ -x /etc/plc.d/$step ] ; then
173 /etc/plc.d/$step stop
174 # Steps may alter the configuration, may need to regenerate
177 echo "PLC: $step: unrecognized step" >&4
199 if [ -z "$cpfile" ] ; then
200 echo "PLC: checkpoint requires a filename as an argument"
203 cpdir=$(mktemp -d tmp.XXXXXX)
205 mkdir -p ./etc/planetlab/
206 rsync -av /etc/planetlab/ ./etc/planetlab/
207 /etc/plc.d/db checkpoint ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
215 cpdir=$(mktemp -d tmp.XXXXXX)
218 /etc/plc.d/db restore ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
219 rm -f ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
220 rsync -av ./etc/planetlab/ /etc/planetlab/
226 echo "${steps[@]}" >&4
229 # for backwards compatibility
230 mount|umount|mountstatus)
231 echo "${command} not used within native myplc environment"