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
38 # do not consider files that contain '.', '~' or 'functions' in the name
40 for step in /etc/plc.d/* ; do
41 stepname=$(basename $step)
42 plainstepname=$(echo $stepname | sed -e 's,\.,,' -e 's,~,,' -e 's,functions,,' )
43 if [ -f $step -a -x $step -a "$stepname" = "$plainstepname" ] ; then
44 priority=$(sed -ne 's/# priority: \(.*\)/\1/p' $step)
45 echo $priority $stepname
47 done | sort -n | cut -d' ' -f2
51 # Regenerate configuration files
56 # Regenerate the main configuration file from default values
57 # overlaid with site-specific and current values.
58 # Thierry -- 2007-07-05 : values in plc_config.xml are *not* taken into account here
60 /etc/planetlab/default_config.xml
61 /etc/planetlab/configs/site.xml
63 for file in "${files[@]}" ; do
64 if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ] ; then
65 tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
66 plc-config --xml "${files[@]}" >$tmp
67 if [ $? -eq 0 ] ; then
68 mv $tmp /etc/planetlab/plc_config.xml
69 chmod 444 /etc/planetlab/plc_config.xml
71 echo "PLC: Warning: Invalid configuration file(s) detected"
78 # Convert configuration to various formats
79 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
80 plc-config --shell >/etc/planetlab/plc_config
82 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ] ; then
83 plc-config --python >/etc/planetlab/plc_config.py
85 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
86 mkdir -p /etc/planetlab/php
87 plc-config --php >/etc/planetlab/php/plc_config.php
93 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
95 echo " -h This message"
98 echo " start Start all PLC subsystems"
99 echo " stop Stop all PLC subsystems"
100 echo " reload Regenerate configuration files"
101 echo " restart Restart all PLC subsystems"
102 echo " checkpoint filename : Checkpoint the current state of MyPLC to filename"
103 echo " restore filename : Restore MyPLC state from filename"
104 echo " steps Displays ordered list of subsystems"
107 for step in "${steps[@]}" ; do
108 if [ -x /etc/plc.d/$step ] ; then
109 echo " $(basename $step)"
116 while getopts "vh" opt ; do
127 # Redirect stdout and stderr of each step to /var/log/boot.log
128 if [ $verbose -eq 0 ] ; then
129 touch /var/log/boot.log
130 chmod 600 /var/log/boot.log
131 exec 1>>/var/log/boot.log
132 exec 2>>/var/log/boot.log
136 shift $(($OPTIND - 1))
137 if [ -z "$1" ] ; then
144 if [ -z "$1" ] ; then
145 # Start or stop everything. Regenerate configuration first.
148 # Start or stop a particular step
157 for step in "${steps[@]}" ; do
158 if [ -x /etc/plc.d/$step ] ; then
159 /etc/plc.d/$step start
160 # Steps may alter the configuration, may need to regenerate
163 echo "PLC: $step: unrecognized step" >&4
171 for i in $(seq 1 $nsteps) ; do
172 step=${steps[$(($nsteps - $i))]}
173 if [ -x /etc/plc.d/$step ] ; then
174 /etc/plc.d/$step stop
175 # Steps may alter the configuration, may need to regenerate
178 echo "PLC: $step: unrecognized step" >&4
200 if [ -z "$cpfile" ] ; then
201 echo "PLC: checkpoint requires a filename as an argument"
204 cpdir=$(mktemp -d tmp.XXXXXX)
206 mkdir -p ./etc/planetlab/
207 rsync -av /etc/planetlab/ ./etc/planetlab/
208 /etc/plc.d/db checkpoint ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
216 cpdir=$(mktemp -d tmp.XXXXXX)
219 /etc/plc.d/db restore ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
220 rm -f ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
221 rsync -av ./etc/planetlab/ /etc/planetlab/
227 echo "${steps[@]}" >&4
230 # for backwards compatibility
231 mount|umount|mountstatus)
232 echo "${command} not used within native myplc environment"