08975dc7adbaaa5039981b415adbd60de2c62dc4
[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     # install peer certs
65     action $"SFA installing peer certs" daemon /usr/bin/sfa-start.py -t -d $OPTIONS 
66
67     if [ "$SFA_REGISTRY_ENABLED" -eq 1 ]; then
68         action $"SFA Registry" daemon /usr/bin/sfa-start.py -r -d $OPTIONS
69     fi
70
71     if [ "$SFA_AGGREGATE_ENABLED" -eq 1 ]; then
72         action $"SFA Aggregate" daemon /usr/bin/sfa-start.py -a -d $OPTIONS
73     fi
74         
75     if [ "$SFA_SM_ENABLED" -eq 1 ]; then
76         action "SFA SliceMgr" daemon /usr/bin/sfa-start.py -s -d $OPTIONS
77     fi
78
79     if [ "$SFA_FLASHPOLICY_ENABLED" -eq 1 ]; then
80         action "Flash Policy Server" daemon /usr/bin/sfa_flashpolicy.py --file="$SFA_FLASHPOLICY_CONFIG_FILE" --port=$SFA_FLASHPOLICY_PORT -d
81     fi
82
83     RETVAL=$?
84     [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sfa-start.py
85
86 }
87
88 stop() {
89     action $"Shutting down SFA" killproc sfa-start.py
90     RETVAL=$?
91
92     [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sfa-start.py
93 }
94
95
96 case "$1" in
97     start) start ;;
98     stop) stop ;;
99     reload) reload force ;;
100     restart) stop; start ;;
101     condrestart)
102         if [ -f /var/lock/subsys/sfa-start.py ]; then
103             stop
104             start
105         fi
106         ;;
107     status)
108         status sfa-start.py
109         RETVAL=$?
110         ;;
111     *)
112         echo $"Usage: $0 {start|stop|reload|restart|condrestart|status}"
113         exit 1
114         ;;
115 esac
116
117 exit $RETVAL
118