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/plc_config.rb ] ; then
85 plc-config --ruby >/etc/planetlab/plc_config.rb
87 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
88 mkdir -p /etc/planetlab/php
89 plc-config --php >/etc/planetlab/php/plc_config.php
95 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
97 echo " -h This message"
100 echo " start Start all PLC subsystems"
101 echo " stop Stop all PLC subsystems"
102 echo " reload Regenerate configuration files"
103 echo " restart Restart all PLC subsystems"
104 echo " checkpoint filename : Checkpoint the current state of MyPLC to filename"
105 echo " restore filename : Restore MyPLC state from filename"
106 echo " steps Displays ordered list of subsystems"
109 for step in "${steps[@]}" ; do
110 if [ -x /etc/plc.d/$step ] ; then
111 echo " $(basename $step)"
118 while getopts "vh" opt ; do
129 # Redirect stdout and stderr of each step to /var/log/boot.log
130 if [ $verbose -eq 0 ] ; then
131 touch /var/log/boot.log
132 chmod 600 /var/log/boot.log
133 exec 1>>/var/log/boot.log
134 exec 2>>/var/log/boot.log
138 shift $(($OPTIND - 1))
139 if [ -z "$1" ] ; then
146 if [ -z "$1" ] ; then
147 # Start or stop everything. Regenerate configuration first.
150 # Start or stop a particular step
159 for step in "${steps[@]}" ; do
160 if [ -x /etc/plc.d/$step ] ; then
161 /etc/plc.d/$step start
162 # Steps may alter the configuration, may need to regenerate
165 echo "PLC: $step: unrecognized step" >&4
173 for i in $(seq 1 $nsteps) ; do
174 step=${steps[$(($nsteps - $i))]}
175 if [ -x /etc/plc.d/$step ] ; then
176 /etc/plc.d/$step stop
177 # Steps may alter the configuration, may need to regenerate
180 echo "PLC: $step: unrecognized step" >&4
202 if [ -z "$cpfile" ] ; then
203 echo "PLC: checkpoint requires a filename as an argument"
206 cpdir=$(mktemp -d tmp.XXXXXX)
208 mkdir -p ./etc/planetlab/
209 rsync -av /etc/planetlab/ ./etc/planetlab/
210 /etc/plc.d/db checkpoint ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
218 cpdir=$(mktemp -d tmp.XXXXXX)
221 /etc/plc.d/db restore ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
222 rm -f ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
223 rsync -av ./etc/planetlab/ /etc/planetlab/
229 echo "${steps[@]}" >&4
232 # for backwards compatibility
233 mount|umount|mountstatus)
234 echo "${command} not used within native myplc environment"