Setting tag plcapi-5.4-2
[plcapi.git] / plc.d / api
1 #!/bin/bash
2 #
3 # priority: 800
4 #
5 # Configure the API. Must be done after SSL certificates are generated
6 # and before the API web server is brought up.
7 #
8 # Mark Huang <mlhuang@cs.princeton.edu>
9 # Copyright (C) 2006 The Trustees of Princeton University
10 #
11
12 # Source function library and configuration
13 . /etc/plc.d/functions
14 . /etc/planetlab/plc_config
15 local_config=/etc/planetlab/configs/site.xml
16
17 # Be verbose
18 set -x
19
20 case "$1" in
21     start)
22         if [ "$PLC_API_ENABLED" != "1" ] ; then
23             exit 0
24         fi
25
26         MESSAGE=$"Configuring the API"
27         dialog "$MESSAGE"
28
29         # Make sure that the API maintenance account is protected by a
30         # password.
31         if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
32             PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
33             plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save=$local_config $local_config
34         #service plc reload
35         plc_reload force
36         fi
37
38         # Make sure that all PLC servers are allowed to access the API
39         # through the maintenance account.
40         PLC_API_MAINTENANCE_SOURCES=($((
41             for ip in $PLC_API_MAINTENANCE_SOURCES ; do
42                 echo $ip
43             done
44             for server in API BOOT WWW ; do
45                 hostname=PLC_${server}_HOST
46                 gethostbyname ${!hostname}
47             done
48         ) | sort -u))
49         PLC_API_MAINTENANCE_SOURCES=${PLC_API_MAINTENANCE_SOURCES[*]}
50         plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save=$local_config $local_config
51         #service plc reload
52         plc_reload force
53
54         result "$MESSAGE"
55         ;;
56 esac
57
58 exit $ERRORS