0c7a4a703fcaff64cdbabc79284dead07798e83e
[myplc.git] / plc.d / api
1 #!/bin/bash
2 #
3 # priority: 450
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 # $Id: api,v 1.5 2006/07/10 21:08:06 mlhuang Exp $
12 #
13
14 # Source function library and configuration
15 . /etc/plc.d/functions
16 . /etc/planetlab/plc_config
17
18 # Be verbose
19 set -x
20
21 case "$1" in
22     start)
23         if [ "$PLC_API_ENABLED" != "1" ] ; then
24             exit 0
25         fi
26
27         MESSAGE=$"Configuring the API"
28         dialog "$MESSAGE"
29
30         # Generate old DB configuration file
31         ln -sf plc_config /etc/planetlab/plc_db
32
33         # Make sure that the API maintenance account is protected by a
34         # password.
35         if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
36             PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
37             plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save
38         fi
39
40         # Make sure that all PLC servers are allowed to access the API
41         # through the maintenance account.
42         PLC_API_MAINTENANCE_SOURCES=$(
43             for server in API BOOT WWW ; do
44                 hostname=PLC_${server}_HOST
45                 gethostbyname ${!hostname}
46             done | sort -u
47         )
48         plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save
49
50         result "$MESSAGE"
51         ;;
52 esac
53
54 exit $ERRORS