one more backport fix, #72101
[freeside.git] / init.d / freeside-init
1 #!/bin/sh
2 #
3 # chkconfig: 345 86 16
4 # description: Freeside daemons
5 #
6 ### BEGIN INIT INFO
7 # Provides:          freeside
8 # Required-Start:    $time $remote_fs
9 # Required-Stop:     $remote_fs
10 # Should-Start:      postgresql mysql
11 # Should-Stop:       postgresql mysql
12 # Default-Start:     2 3 4 5
13 # Default-Stop:      0 1 6
14 # Short-Description: Start Freeside daemons at boot time
15 # Description:       Enable Freeside daemons
16 ### END INIT INFO
17
18 QUEUED_USER=%%%QUEUED_USER%%%
19 API_USER=%%%API_USER%%%
20
21 SELFSERVICE_USER=%%%SELFSERVICE_USER%%%
22 SELFSERVICE_MACHINES="%%%SELFSERVICE_MACHINES%%%"
23
24 IF=eth0
25
26 #INSTALLSCRIPT/INSTALLSITEBIN from Makefile.PL
27 PATH="$PATH:/usr/local/bin"
28 export PATH
29
30 [ -r /etc/default/freeside ] && . /etc/default/freeside
31
32 case "$1" in
33   start)
34         # Start daemons.
35
36         for MACHINE in $SELFSERVICE_MACHINES; do
37           echo -n "Starting freeside-selfservice-server to $MACHINE: "
38           freeside-selfservice-server $SELFSERVICE_USER $MACHINE
39           echo "done."
40         done
41
42         echo -n "Starting freeside-selfservice-xmlrpcd: "
43         freeside-selfservice-xmlrpcd $SELFSERVICE_USER
44         echo "done."
45
46         echo -n "Starting freeside-xmlrpcd: "
47         freeside-xmlrpcd $API_USER
48         echo "done."
49
50 #        echo -n "Starting freeside-jsonrpcd: "
51 #        freeside-jsonrpcd $API_USER
52 #        echo "done."
53
54         echo -n "Starting freeside-queued: "
55         #perl -MDBIx::Profile /usr/local/bin/freeside-queued $QUEUED_USER
56         freeside-queued $QUEUED_USER
57         #export NYTPROF="file=/usr/local/etc/freeside/nytprof.out"
58         #PERL5OPT="-d:NYTProf" freeside-queued $QUEUED_USER
59         echo "done."
60
61         echo -n "Starting freeside-sqlradius-radacctd: "
62         freeside-sqlradius-radacctd $QUEUED_USER
63         echo "done."
64
65         echo -n "Starting freeside-prepaidd: "
66         freeside-prepaidd $QUEUED_USER
67         echo "done."
68
69         echo -n "Starting freeside-cdrrewrited: "
70         freeside-cdrrewrited $QUEUED_USER
71         echo "done."
72
73         echo -n "Starting freeside-cdrd: "
74         freeside-cdrd $QUEUED_USER
75         echo "done."
76
77         echo -n "Starting freeside-cdrrated: "
78         freeside-cdrrated $QUEUED_USER
79         echo "done."
80
81         if [ -e /usr/local/bin/torrus ]; then
82           echo -n "Starting torrus collector: "
83           /usr/local/bin/torrus collector --tree=main
84           echo "done."
85         fi
86
87         echo -n "Starting freeside-torrus-srvderive: "
88         freeside-torrus-srvderive $QUEUED_USER
89         echo "done."
90
91         if [ -e /opt/rt3/etc/RT_SiteConfig.pm.ORIG_WEBDEMO_HACK ]; then
92           ip=`/sbin/ifconfig $IF | grep 'inet addr:' | cut -d: -f2- | cut -d' ' -f1`
93           cp /opt/rt3/etc/RT_SiteConfig.pm.ORIG_WEBDEMO_HACK /opt/rt3/etc/RT_SiteConfig.pm
94           perl -pi -e "s/localhost/$ip/" /opt/rt3/etc/RT_SiteConfig.pm
95         fi
96
97         ;;
98   stop)
99         # Stop daemons.
100         echo -n "Stopping freeside-queued: "
101         [ -e /var/run/freeside-queued.pid ] && kill `cat /var/run/freeside-queued.pid`
102         #and
103         sleep 2;
104         killall freeside-queued
105         echo "done."
106
107         if [ -e /var/run/freeside-sqlradius-radacctd.pid ]; then
108           echo -n "Stopping freeside-sqlradius-radacctd: "
109           kill `cat /var/run/freeside-sqlradius-radacctd.pid`
110           echo "done."
111         fi
112
113         if [ -e /var/run/freeside-prepaidd.pid ]; then
114           echo -n "Stopping freeside-prepaidd: "
115           kill `cat /var/run/freeside-prepaidd.pid`
116           echo "done."
117         fi
118
119         if [ -e /var/run/freeside-cdrd.pid ]; then
120           echo -n "Stopping freeside-cdrd: "
121           kill `cat /var/run/freeside-cdrd.pid`
122           echo "done."
123         fi
124
125         if [ -e /var/run/freeside-cdrrewrited.pid ]; then
126           echo -n "Stopping freeside-cdrrewrited: "
127           kill `cat /var/run/freeside-cdrrewrited.pid`
128           echo "done."
129         fi
130
131         if [ -e /var/run/freeside-cdrrated.pid ]; then
132           echo -n "Stopping freeside-cdrrated: "
133           kill `cat /var/run/freeside-cdrrated.pid`
134           echo "done."
135         fi
136
137         if [ -e /var/run/freeside/torrus-srvderive.pid ]; then
138           echo -n "Stopping freeside-torrus-srvderive: "
139           kill `cat /var/run/freeside/torrus-srvderive.pid`
140           echo "done."
141         fi
142
143         if [ -e /var/run/torrus/collector.main_?.pid ]; then
144           echo -n "Stopping torrus collector: "
145           kill `cat /var/run/torrus/collector.main_?.pid`
146           echo "done."
147         fi
148
149         if [ -e /var/run/freeside/xmlrpcd.pid ]; then
150           echo -n "Stopping freeside-xmlrpcd: "
151           kill `cat /var/run/freeside/xmlrpcd.pid`
152           echo "done."
153         fi
154
155 #        if [ -e /var/run/freeside/jsonrpcd.pid ]; then
156 #          echo -n "Stopping freeside-jsonrpcd: "
157 #          kill `cat /var/run/freeside/jsonrpcd.pid`
158 #          echo "done."
159 #        fi
160
161         if [ -e /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid ]
162         then
163           echo -n "Stopping (old) freeside-selfservice-server: "
164           kill `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid`
165           sleep 
166           rm /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid
167           echo "done."
168         fi
169
170         if [ -z "$SELFSERVICE_MACHINES" ]; then SELFSERVICE_MACHINES='localhost'; fi
171         for MACHINE in $SELFSERVICE_MACHINES; do
172           if [ -e /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid ]
173           then
174             echo -n "Stopping freeside-selfservice-server to $MACHINE"
175             kill `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid`
176             howlong=10
177             while [ $howlong -gt 0 ] && kill -0 `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid` 2>/dev/null; do
178               echo -n '.'
179               sleep 1
180               howlong=$(( $howlong - 1 ))
181               if [ $howlong -eq 0 ]; then
182                 echo -n 'forcefully.'
183                 kill -9 `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid`
184               fi
185             done
186             echo "done."
187             rm /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid
188           fi
189         done
190
191         if [ -e /var/run/freeside/selfservice-xmlrpcd.pid ]; then
192           echo -n "Stopping freeside-selfservice-xmlrpcd: "
193           kill `cat /var/run/freeside/selfservice-xmlrpcd.pid`
194           echo "done."
195         fi
196
197         ;;
198
199   restart)
200         $0 stop
201         $0 start
202         ;;
203   *)
204         echo "Usage: freeside {start|stop|restart}"
205         exit 1
206 esac
207
208 exit 0
209