3 # plc Manages all PLC services on this machine
5 # chkconfig: 2345 60 40
7 # description: Manages all PLC services on this machine
10 # Source function library and configuration
11 . /etc/plc.d/functions
16 # All steps should be idempotent. This means that you should be able
17 # to run them multiple times without depending on anything previously
18 # being run. The idea is that when the configuration changes, "service
19 # plc restart" is called, all dependencies are fixed up, and
20 # everything just works.
23 # we want the resulting myplc to be able to easily skip
24 # some steps. e.g. the packages step takes ages if you install
25 # all rpms under the repository.
26 # We skip steps whose name contains a dot (.) or a tilde (~)
27 # this way the operations would just rename a step name e.g.
29 # mv packages packages.hide
31 # The drawback is, this stuff does not survive an rpm update
32 # but that's maybe a good thing, that all is done at first start
35 # do not consider files that contain '.', '~' or 'functions' in the name
37 for step in /etc/plc.d/* ; do
38 stepname=$(basename $step)
39 plainstepname=$(echo $stepname | sed -e 's,\.,,' -e 's,~,,' -e 's,functions,,' )
40 if [ -f $step -a -x $step -a "$stepname" = "$plainstepname" ] ; then
41 priority=$(sed -ne 's/# priority: \(.*\)/\1/p' $step)
42 echo $priority $stepname
44 done | sort -n | cut -d' ' -f2
48 # Regenerate configuration files
53 # Regenerate the main configuration file from default values
54 # overlaid with site-specific and current values.
55 # Thierry -- 2007-07-05 : values in plc_config.xml are *not* taken into account here
57 /etc/planetlab/default_config.xml
58 /etc/planetlab/configs/site.xml
60 for file in "${files[@]}" ; do
61 if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ] ; then
62 tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
63 plc-config --xml "${files[@]}" >$tmp
64 if [ $? -eq 0 ] ; then
65 mv $tmp /etc/planetlab/plc_config.xml
66 chmod 444 /etc/planetlab/plc_config.xml
68 echo "PLC: Warning: Invalid configuration file(s) detected"
75 # Convert configuration to various formats
76 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
77 plc-config --shell >/etc/planetlab/plc_config
79 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ] ; then
80 plc-config --python >/etc/planetlab/plc_config.py
82 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
83 mkdir -p /etc/planetlab/php
84 plc-config --php >/etc/planetlab/php/plc_config.php
90 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
92 echo " -h This message"
95 echo " start Start all PLC subsystems"
96 echo " stop Stop all PLC subsystems"
97 echo " reload Regenerate configuration files"
98 echo " restart Restart all PLC subsystems"
99 echo " checkpoint filename : Checkpoint the current state of MyPLC to filename"
100 echo " restore filename : Restore MyPLC state from filename"
101 echo " steps Displays ordered list of subsystems"
104 for step in "${steps[@]}" ; do
105 if [ -x /etc/plc.d/$step ] ; then
106 echo " $(basename $step)"
113 while getopts "vh" opt ; do
124 # Redirect stdout and stderr of each step to /var/log/boot.log
125 if [ $verbose -eq 0 ] ; then
126 touch /var/log/boot.log
127 chmod 600 /var/log/boot.log
128 exec 1>>/var/log/boot.log
129 exec 2>>/var/log/boot.log
133 shift $(($OPTIND - 1))
134 if [ -z "$1" ] ; then
141 if [ -z "$1" ] ; then
142 # Start or stop everything. Regenerate configuration first.
145 # Start or stop a particular step
154 for step in "${steps[@]}" ; do
155 if [ -x /etc/plc.d/$step ] ; then
156 /etc/plc.d/$step start
157 # Steps may alter the configuration, may need to regenerate
160 echo "PLC: $step: unrecognized step" >&4
168 for i in $(seq 1 $nsteps) ; do
169 step=${steps[$(($nsteps - $i))]}
170 if [ -x /etc/plc.d/$step ] ; then
171 /etc/plc.d/$step stop
172 # Steps may alter the configuration, may need to regenerate
175 echo "PLC: $step: unrecognized step" >&4
197 if [ -z "$cpfile" ] ; then
198 echo "PLC: checkpoint requires a filename as an argument"
201 cpdir=$(mktemp -d tmp.XXXXXX)
203 mkdir -p ./etc/planetlab/
204 rsync -av /etc/planetlab/ ./etc/planetlab/
205 /etc/plc.d/db checkpoint ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
213 cpdir=$(mktemp -d tmp.XXXXXX)
216 /etc/plc.d/db restore ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
217 rm -f ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
218 rsync -av ./etc/planetlab/ /etc/planetlab/
224 echo "${steps[@]}" >&4
227 # for backwards compatibility
228 mount|umount|mountstatus)
229 echo "${command} not used within native myplc environment"