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