1b9bc0384a3f6523e0c8ce18012ba4a49a455dec
[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.6 2007/01/18 18:44:18 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         # Make sure that the API maintenance account is protected by a
31         # password.
32         if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
33             PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
34             plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save
35         fi
36
37         # Make sure that all PLC servers are allowed to access the API
38         # through the maintenance account.
39         for server in API BOOT WWW ; do
40             hostname=PLC_${server}_HOST
41             ip=$(gethostbyname ${!hostname})
42             if [ -n "$ip" ] ; then
43                 if [ -z "$PLC_API_MAINTENANCE_SOURCES" ] ; then
44                     PLC_API_MAINTENANCE_SOURCES=$ip
45                 else
46                     PLC_API_MAINTENANCE_SOURCES="$PLC_API_MAINTENANCE_SOURCES $ip"
47                 fi
48             fi
49         done
50         plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save
51
52         # Bootstrap the DB
53         db-config
54         check
55
56         result "$MESSAGE"
57         ;;
58 esac
59
60 exit $ERRORS