3 # plc Manages all PLC services on this machine
7 # description: Manages all PLC services on this machine
9 # $Id: guest.init,v 1.17 2006/04/27 21:50:00 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
36 # Regenerate the main configuration file from default values
37 # overlaid with site-specific and current values.
38 tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
40 /etc/planetlab/default_config.xml \
41 /etc/planetlab/configs/* \
42 /etc/planetlab/plc_config.xml \
44 if [ $? -eq 0 ] ; then
45 mv $tmp /etc/planetlab/plc_config.xml
46 chmod 644 /etc/planetlab/plc_config.xml
48 echo "PLC: Warning: Invalid configuration file(s) detected"
53 plc-config --shell >/etc/planetlab/plc_config
54 . /etc/planetlab/plc_config
56 # Generate various defaults
57 if [ -z "$PLC_DB_PASSWORD" ] ; then
58 PLC_DB_PASSWORD=$(uuidgen)
59 plc-config --category=plc_db --variable=password --value="$PLC_DB_PASSWORD" --save
62 if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
63 PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
64 plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save
67 # Need to configure network before resolving hostnames
68 /etc/plc.d/network start 3>/dev/null 4>/dev/null
70 PLC_API_MAINTENANCE_SOURCES=$(
71 for server in API BOOT WWW ; do
72 hostname=PLC_${server}_HOST
73 gethostbyname ${!hostname}
76 plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save
79 mkdir -p /etc/planetlab/php
80 plc-config --php >/etc/planetlab/php/plc_config.php
81 plc-config --shell >/etc/planetlab/plc_config
83 # For backward compatibility, until we can convert all code to use
84 # the now standardized variable names.
86 # DB constants are all named the same
87 ln -sf plc_config /etc/planetlab/plc_db
90 cat >/etc/planetlab/php/site_constants.php <<"EOF"
92 include('plc_config.php');
94 define('PL_API_SERVER', PLC_API_HOST);
95 define('PL_API_PATH', PLC_API_PATH);
96 define('PL_API_PORT', PLC_API_PORT);
97 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
98 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
99 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
100 define('WWW_BASE', PLC_WWW_HOST);
101 define('BOOT_BASE', PLC_BOOT_HOST);
102 define('DEBUG', PLC_WWW_DEBUG);
103 define('API_CALL_DEBUG', PLC_API_DEBUG);
104 define('SENDMAIL', PLC_MAIL_ENABLED);
105 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
106 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
110 # API constants are written in plc.d/api
115 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
116 echo " -v Be verbose"
117 echo " -h This message"
120 echo " start Start all PLC subsystems"
121 echo " stop Stop all PLC subsystems"
122 echo " reload Regenerate configuration files"
123 echo " restart Restart all PLC subsystems"
126 for step in "${steps[@]}" ; do
127 if [ -x /etc/plc.d/$step ] ; then
128 echo " $(basename $step)"
135 while getopts "vh" opt ; do
146 # Redirect stdout and stderr of each step to /var/log/boot.log
147 if [ $verbose -eq 0 ] ; then
148 touch /var/log/boot.log
149 chmod 600 /var/log/boot.log
150 exec 1>>/var/log/boot.log
151 exec 2>>/var/log/boot.log
155 shift $(($OPTIND - 1))
156 if [ -z "$1" ] ; then
163 if [ -z "$1" ] ; then
164 # Start or stop everything. Regenerate configuration first.
167 # Start or stop a particular step
176 for step in "${steps[@]}" ; do
177 if [ -x /etc/plc.d/$step ] ; then
178 /etc/plc.d/$step start
180 echo "PLC: $step: unrecognized step" >&4
188 for i in $(seq 1 $nsteps) ; do
189 step=${steps[$(($nsteps - $i))]}
190 if [ -x /etc/plc.d/$step ] ; then
191 /etc/plc.d/$step stop
193 echo "PLC: $step: unrecognized step" >&4