3 # plc Manages all PLC services on this machine
7 # description: Manages all PLC services on this machine
9 # $Id: guest.init,v 1.13 2006/04/06 21:51:59 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 values.
39 /etc/planetlab/default_config.xml \
40 /etc/planetlab/configs/* \
41 >/etc/planetlab/plc_config.xml
44 plc-config --shell >/etc/planetlab/plc_config
45 . /etc/planetlab/plc_config
47 # Generate various defaults
48 if [ -z "$PLC_DB_PASSWORD" ] ; then
49 PLC_DB_PASSWORD=$(uuidgen)
50 plc-config --category=plc_db --variable=password --value="$PLC_DB_PASSWORD" --save
53 if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
54 PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
55 plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save
58 # Need to configure network before resolving hostnames
59 /etc/plc.d/network start 3>/dev/null 4>/dev/null
61 PLC_API_MAINTENANCE_SOURCES=$(
62 for server in API BOOT WWW ; do
63 hostname=PLC_${server}_HOST
64 gethostbyname ${!hostname}
67 plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save
70 mkdir -p /etc/planetlab/php
71 plc-config --php >/etc/planetlab/php/plc_config.php
72 plc-config --shell >/etc/planetlab/plc_config
74 # For backward compatibility, until we can convert all code to use
75 # the now standardized variable names.
77 # DB constants are all named the same
78 ln -sf plc_config /etc/planetlab/plc_db
81 cat >/etc/planetlab/plc_api <<EOF
82 PL_API_SERVER='$PLC_API_HOST'
83 PL_API_PATH='$PLC_API_PATH'
84 PL_API_PORT=$PLC_API_PORT
85 PL_API_CAPABILITY_AUTH_METHOD='capability'
86 PL_API_CAPABILITY_PASS='$PLC_API_MAINTENANCE_PASSWORD'
87 PL_API_CAPABILITY_USERNAME='$PLC_API_MAINTENANCE_USER'
88 PL_API_TICKET_KEY_FILE='$PLC_API_SSL_KEY'
89 PLANETLAB_SUPPORT_EMAIL='$PLC_MAIL_SUPPORT_ADDRESS'
90 BOOT_MESSAGES_EMAIL='$PLC_MAIL_BOOT_ADDRESS'
91 WWW_BASE='$PLC_WWW_HOST'
92 BOOT_BASE='$PLC_BOOT_HOST'
95 # API expects root SSH public key to be at /etc/planetlab/node_root_key
96 ln -sf "$PLC_ROOT_SSH_KEY_PUB" /etc/planetlab/node_root_key
100 # ip:max_role_id:organization_id:password
102 # It is unlikely that we will let federated sites use the
103 # maintenance account to access each others' APIs, so we always
104 # set organization_id to -1.
106 echo -n "PL_API_CAPABILITY_SOURCES='"
108 for ip in $PLC_API_MAINTENANCE_SOURCES ; do
109 if [ $first -ne 1 ] ; then
113 echo -n "$ip:-1:-1:$PLC_API_MAINTENANCE_PASSWORD"
116 ) >>/etc/planetlab/plc_api
118 cat >/etc/planetlab/php/site_constants.php <<"EOF"
120 include('plc_config.php');
122 define('PL_API_SERVER', PLC_API_HOST);
123 define('PL_API_PATH', PLC_API_PATH);
124 define('PL_API_PORT', PLC_API_PORT);
125 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
126 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
127 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
128 define('WWW_BASE', PLC_WWW_HOST);
129 define('BOOT_BASE', PLC_BOOT_HOST);
130 define('DEBUG', PLC_WWW_DEBUG);
131 define('API_CALL_DEBUG', PLC_API_DEBUG);
132 define('SENDMAIL', PLC_MAIL_ENABLED);
133 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . 'Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
134 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
141 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
142 echo " -v Be verbose"
143 echo " -h This message"
146 echo " start Start all PLC subsystems"
147 echo " stop Stop all PLC subsystems"
148 echo " reload Regenerate configuration files"
149 echo " restart Restart all PLC subsystems"
152 for step in "${steps[@]}" ; do
153 if [ -x /etc/plc.d/$step ] ; then
154 echo " $(basename $step)"
161 while getopts "vh" opt ; do
172 # Redirect stdout and stderr of each step to /var/log/boot.log
173 if [ $verbose -eq 0 ] ; then
174 exec 1>>/var/log/boot.log
175 exec 2>>/var/log/boot.log
179 shift $(($OPTIND - 1))
180 if [ -z "$1" ] ; then
187 if [ -z "$1" ] ; then
188 # Start or stop everything. Regenerate configuration first.
191 # Start or stop a particular step
200 for step in "${steps[@]}" ; do
201 if [ -x /etc/plc.d/$step ] ; then
202 /etc/plc.d/$step start
204 echo "PLC: $step: unrecognized step" >&4
212 for i in $(seq 1 $nsteps) ; do
213 step=${steps[$(($nsteps - $i))]}
214 if [ -x /etc/plc.d/$step ] ; then
215 /etc/plc.d/$step stop
217 echo "PLC: $step: unrecognized step" >&4