3 # plc Manages all PLC services on this machine
7 # description: Manages all PLC services on this machine
9 # $Id: guest.init,v 1.12 2006/04/04 22:09:47 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
37 plc-config --shell >/etc/planetlab/plc_config
38 . /etc/planetlab/plc_config
40 # Generate various defaults
41 if [ -z "$PLC_DB_PASSWORD" ] ; then
42 PLC_DB_PASSWORD=$(uuidgen)
43 plc-config --category=plc_db --variable=password --value="$PLC_DB_PASSWORD" --save
46 if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
47 PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
48 plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save
51 # Need to configure network before resolving hostnames
52 /etc/plc.d/network start 3>/dev/null 4>/dev/null
54 PLC_API_MAINTENANCE_SOURCES=$(
55 for server in API BOOT WWW ; do
56 hostname=PLC_${server}_HOST
57 gethostbyname ${!hostname}
60 plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save
63 mkdir -p /etc/planetlab/php
64 plc-config --php >/etc/planetlab/php/plc_config.php
65 plc-config --shell >/etc/planetlab/plc_config
67 # For backward compatibility, until we can convert all code to use
68 # the now standardized variable names.
70 # DB constants are all named the same
71 ln -sf plc_config /etc/planetlab/plc_db
74 cat >/etc/planetlab/plc_api <<EOF
75 PL_API_SERVER='$PLC_API_HOST'
76 PL_API_PATH='$PLC_API_PATH'
77 PL_API_PORT=$PLC_API_PORT
78 PL_API_CAPABILITY_AUTH_METHOD='capability'
79 PL_API_CAPABILITY_PASS='$PLC_API_MAINTENANCE_PASSWORD'
80 PL_API_CAPABILITY_USERNAME='$PLC_API_MAINTENANCE_USER'
81 PL_API_TICKET_KEY_FILE='$PLC_API_SSL_KEY'
82 PLANETLAB_SUPPORT_EMAIL='$PLC_MAIL_SUPPORT_ADDRESS'
83 BOOT_MESSAGES_EMAIL='$PLC_MAIL_BOOT_ADDRESS'
84 WWW_BASE='$PLC_WWW_HOST'
85 BOOT_BASE='$PLC_BOOT_HOST'
88 # API expects root SSH public key to be at /etc/planetlab/node_root_key
89 ln -sf "$PLC_ROOT_SSH_KEY_PUB" /etc/planetlab/node_root_key
93 # ip:max_role_id:organization_id:password
95 # It is unlikely that we will let federated sites use the
96 # maintenance account to access each others' APIs, so we always
97 # set organization_id to -1.
99 echo -n "PL_API_CAPABILITY_SOURCES='"
101 for ip in $PLC_API_MAINTENANCE_SOURCES ; do
102 if [ $first -ne 1 ] ; then
106 echo -n "$ip:-1:-1:$PLC_API_MAINTENANCE_PASSWORD"
109 ) >>/etc/planetlab/plc_api
111 cat >/etc/planetlab/php/site_constants.php <<"EOF"
113 include('plc_config.php');
115 define('PL_API_SERVER', PLC_API_HOST);
116 define('PL_API_PATH', PLC_API_PATH);
117 define('PL_API_PORT', PLC_API_PORT);
118 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
119 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
120 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
121 define('WWW_BASE', PLC_WWW_HOST);
122 define('BOOT_BASE', PLC_BOOT_HOST);
123 define('DEBUG', PLC_WWW_DEBUG);
124 define('API_CALL_DEBUG', PLC_API_DEBUG);
125 define('SENDMAIL', PLC_MAIL_ENABLED);
126 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . 'Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
127 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
134 echo "Usage: $0 [OPTION]... [COMMAND] [STEP]..."
135 echo " -v Be verbose"
136 echo " -h This message"
139 echo " start Start all PLC subsystems"
140 echo " stop Stop all PLC subsystems"
141 echo " reload Regenerate configuration files"
142 echo " restart Restart all PLC subsystems"
145 for step in "${steps[@]}" ; do
146 if [ -x /etc/plc.d/$step ] ; then
147 echo " $(basename $step)"
154 while getopts "vh" opt ; do
165 # Redirect stdout and stderr of each step to /var/log/boot.log
166 if [ $verbose -eq 0 ] ; then
167 exec 1>>/var/log/boot.log
168 exec 2>>/var/log/boot.log
172 shift $(($OPTIND - 1))
173 if [ -z "$1" ] ; then
180 if [ -z "$1" ] ; then
181 # Start or stop everything. Regenerate configuration first.
184 # Start or stop a particular step
193 for step in "${steps[@]}" ; do
194 if [ -x /etc/plc.d/$step ] ; then
195 /etc/plc.d/$step start
197 echo "PLC: $step: unrecognized step" >&4
205 for i in $(seq 1 $nsteps) ; do
206 step=${steps[$(($nsteps - $i))]}
207 if [ -x /etc/plc.d/$step ] ; then
208 /etc/plc.d/$step stop
210 echo "PLC: $step: unrecognized step" >&4