3 # plc Manages all PLC services on this machine
7 # description: Manages all PLC services on this machine
9 # $Id: guest.init,v 1.14 2006/04/10 18:18:14 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 [ -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/plc_api <<EOF
91 PL_API_SERVER='$PLC_API_HOST'
92 PL_API_PATH='$PLC_API_PATH'
93 PL_API_PORT=$PLC_API_PORT
94 PL_API_CAPABILITY_AUTH_METHOD='capability'
95 PL_API_CAPABILITY_PASS='$PLC_API_MAINTENANCE_PASSWORD'
96 PL_API_CAPABILITY_USERNAME='$PLC_API_MAINTENANCE_USER'
97 PL_API_TICKET_KEY_FILE='$PLC_API_SSL_KEY'
98 PLANETLAB_SUPPORT_EMAIL='$PLC_MAIL_SUPPORT_ADDRESS'
99 BOOT_MESSAGES_EMAIL='$PLC_MAIL_BOOT_ADDRESS'
100 WWW_BASE='$PLC_WWW_HOST'
101 BOOT_BASE='$PLC_BOOT_HOST'
104 # API expects root SSH public key to be at /etc/planetlab/node_root_key
105 ln -sf "$PLC_ROOT_SSH_KEY_PUB" /etc/planetlab/node_root_key
109 # ip:max_role_id:organization_id:password
111 # It is unlikely that we will let federated sites use the
112 # maintenance account to access each others' APIs, so we always
113 # set organization_id to -1.
115 echo -n "PL_API_CAPABILITY_SOURCES='"
117 for ip in $PLC_API_MAINTENANCE_SOURCES ; do
118 if [ $first -ne 1 ] ; then
122 echo -n "$ip:-1:-1:$PLC_API_MAINTENANCE_PASSWORD"
125 ) >>/etc/planetlab/plc_api
127 cat >/etc/planetlab/php/site_constants.php <<"EOF"
129 include('plc_config.php');
131 define('PL_API_SERVER', PLC_API_HOST);
132 define('PL_API_PATH', PLC_API_PATH);
133 define('PL_API_PORT', PLC_API_PORT);
134 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
135 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
136 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
137 define('WWW_BASE', PLC_WWW_HOST);
138 define('BOOT_BASE', PLC_BOOT_HOST);
139 define('DEBUG', PLC_WWW_DEBUG);
140 define('API_CALL_DEBUG', PLC_API_DEBUG);
141 define('SENDMAIL', PLC_MAIL_ENABLED);
142 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . 'Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
143 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
150 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
151 echo " -v Be verbose"
152 echo " -h This message"
155 echo " start Start all PLC subsystems"
156 echo " stop Stop all PLC subsystems"
157 echo " reload Regenerate configuration files"
158 echo " restart Restart all PLC subsystems"
161 for step in "${steps[@]}" ; do
162 if [ -x /etc/plc.d/$step ] ; then
163 echo " $(basename $step)"
170 while getopts "vh" opt ; do
181 # Redirect stdout and stderr of each step to /var/log/boot.log
182 if [ $verbose -eq 0 ] ; then
183 exec 1>>/var/log/boot.log
184 exec 2>>/var/log/boot.log
188 shift $(($OPTIND - 1))
189 if [ -z "$1" ] ; then
196 if [ -z "$1" ] ; then
197 # Start or stop everything. Regenerate configuration first.
200 # Start or stop a particular step
209 for step in "${steps[@]}" ; do
210 if [ -x /etc/plc.d/$step ] ; then
211 /etc/plc.d/$step start
213 echo "PLC: $step: unrecognized step" >&4
221 for i in $(seq 1 $nsteps) ; do
222 step=${steps[$(($nsteps - $i))]}
223 if [ -x /etc/plc.d/$step ] ; then
224 /etc/plc.d/$step stop
226 echo "PLC: $step: unrecognized step" >&4