Merge branch 'master' into eucalyptus-devel
[sfa.git] / sfa / init.d / sfa
1 #!/bin/bash
2 #
3 # sfa   Wraps PLCAPI into the SFA compliant API
4 #
5 # hopefully right after plc
6 # chkconfig: 2345 61 39
7 #
8 # description:   Wraps PLCAPI into the SFA compliant API
9 #
10
11 # Source config
12 [ -f /etc/sfa/sfa_config ] && . /etc/sfa/sfa_config
13
14 # source function library
15 . /etc/init.d/functions
16
17 # Regenerate configuration files - almost verbatim from plc.init
18 reload ()
19 {
20     force=$1
21
22     # Regenerate the main configuration file from default values
23     # overlaid with site-specific and current values.
24     # Thierry -- 2007-07-05 : values in plc_config.xml are *not* taken into account here
25     files=(
26         /etc/sfa/default_config.xml 
27         /etc/sfa/configs/site.xml
28     )
29     for file in "${files[@]}" ; do
30         if [ -n "$force" -o $file -nt /etc/sfa/sfa_config.xml ] ; then
31             tmp=$(mktemp /tmp/sfa_config.xml.XXXXXX)
32             plc-config --xml "${files[@]}" >$tmp
33             if [ $? -eq 0 ] ; then
34                 mv $tmp /etc/sfa/sfa_config.xml
35                 chmod 444 /etc/sfa/sfa_config.xml
36             else
37                 echo "SFA: Warning: Invalid configuration file(s) detected"
38                 rm -f $tmp
39             fi
40             break
41         fi
42     done
43
44     # Convert configuration to various formats
45     if [ -n "$force" -o /etc/sfa/sfa_config.xml -nt /etc/sfa/sfa_config ] ; then
46         plc-config --shell /etc/sfa/sfa_config.xml >/etc/sfa/sfa_config
47     fi
48     if [ -n "$force" -o /etc/sfa/sfa_config.xml -nt /etc/sfa/sfa_config.py ] ; then
49         plc-config --python /etc/sfa/sfa_config.xml >/etc/sfa/sfa_config.py
50     fi
51 #    if [ -n "$force" -o /etc/sfa/sfa_config.xml -nt /etc/sfa/php/sfa_config.php ] ; then
52 #       mkdir -p /etc/sfa/php
53 #       plc-config --php  /etc/sfa/sfa_config.xml >/etc/sfa/php/sfa_config.php
54 #    fi
55
56     # [re]generate the sfa_component_config
57     gen-sfa-cm-config.py        
58 }
59
60 start() {
61     
62     reload
63
64     if [ "$SFA_REGISTRY_ENABLED" -eq 1 ]; then
65         action $"SFA Registry" daemon /usr/bin/sfa-server.py -r -d $OPTIONS
66     fi
67
68     if [ "$SFA_AGGREGATE_ENABLED" -eq 1 ]; then
69         action $"SFA Aggregate" daemon /usr/bin/sfa-server.py -a -d $OPTIONS
70     fi
71         
72     if [ "$SFA_SM_ENABLED" -eq 1 ]; then
73         action "SFA SliceMgr" daemon /usr/bin/sfa-server.py -s -d $OPTIONS
74     fi
75
76     if [ "$SFA_FLASHPOLICY_ENABLED" -eq 1 ]; then
77         action "Flash Policy Server" daemon /usr/bin/sfa_flashpolicy.py --file="$SFA_FLASHPOLICY_CONFIG_FILE" --port=$SFA_FLASHPOLICY_PORT -d
78     fi
79
80     RETVAL=$?
81     [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sfa-server.py
82
83 }
84
85 stop() {
86     action $"Shutting down SFA" killproc sfa-server.py
87     RETVAL=$?
88
89     [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sfa-server.py
90 }
91
92
93 case "$1" in
94     start) start ;;
95     stop) stop ;;
96     reload) reload force ;;
97     restart) stop; start ;;
98     condrestart)
99         if [ -f /var/lock/subsys/sfa-server.py ]; then
100             stop
101             start
102         fi
103         ;;
104     status)
105         status sfa-server.py
106         RETVAL=$?
107         ;;
108     *)
109         echo $"Usage: $0 {start|stop|reload|restart|condrestart|status}"
110         exit 1
111         ;;
112 esac
113
114 exit $RETVAL
115