combine ticket notification scrips, #15353
[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
20 SELFSERVICE_USER=%%%SELFSERVICE_USER%%%
21 SELFSERVICE_MACHINES="%%%SELFSERVICE_MACHINES%%%"
22
23 IF=eth0
24
25 #INSTALLSCRIPT/INSTALLSITEBIN from Makefile.PL
26 PATH="$PATH:/usr/local/bin"
27 export PATH
28
29 [ -r /etc/default/freeside ] && . /etc/default/freeside
30
31 case "$1" in
32   start)
33         # Start daemons.
34         echo -n "Starting freeside-queued: "
35         #perl -MDBIx::Profile /usr/local/bin/freeside-queued $QUEUED_USER
36         freeside-queued $QUEUED_USER
37         #export NYTPROF="file=/usr/local/etc/freeside/nytprof.out"
38         #PERL5OPT="-d:NYTProf" freeside-queued $QUEUED_USER
39         echo "done."
40
41         echo -n "Starting freeside-sqlradius-radacctd: "
42         freeside-sqlradius-radacctd $QUEUED_USER
43         echo "done."
44
45         echo -n "Starting freeside-prepaidd: "
46         freeside-prepaidd $QUEUED_USER
47         echo "done."
48
49         echo -n "Starting freeside-cdrrewrited: "
50         freeside-cdrrewrited $QUEUED_USER
51         echo "done."
52
53         echo -n "Starting freeside-cdrd: "
54         freeside-cdrd $QUEUED_USER
55         echo "done."
56
57         for MACHINE in $SELFSERVICE_MACHINES; do
58           echo -n "Starting freeside-selfservice-server to $MACHINE: "
59           freeside-selfservice-server $SELFSERVICE_USER $MACHINE
60           echo "done."
61         done
62
63         echo -n "Starting freeside-selfservice-xmlrpcd: "
64         freeside-selfservice-xmlrpcd $SELFSERVICE_USER
65         echo "done."
66
67         if [ -e /usr/local/bin/torrus ]; then
68           echo -n "Starting torrus collector: "
69           /usr/local/bin/torrus collector --tree=main
70           echo "done."
71         fi
72
73         echo -n "Starting freeside-torrus-srvderive: "
74         freeside-torrus-srvderive $QUEUED_USER
75         echo "done."
76
77         #ip=`/sbin/ifconfig $IF | grep 'inet addr:' | cut -d: -f2- | cut -d' ' -f1`
78         #cp /opt/rt3/etc/RT_SiteConfig.pm.ORIG /opt/rt3/etc/RT_SiteConfig.pm
79         #perl -pi -e "s/localhost/$ip/" /opt/rt3/etc/RT_SiteConfig.pm
80
81         ;;
82   stop)
83         # Stop daemons.
84         echo -n "Stopping freeside-queued: "
85         [ -e /var/run/freeside-queued.pid ] && kill `cat /var/run/freeside-queued.pid`
86         #and
87         sleep 2;
88         killall freeside-queued
89         echo "done."
90
91         if [ -e /var/run/freeside-sqlradius-radacctd.pid ]; then
92           echo -n "Stopping freeside-sqlradius-radacctd: "
93           kill `cat /var/run/freeside-sqlradius-radacctd.pid`
94           echo "done."
95         fi
96
97         if [ -e /var/run/freeside-prepaidd.pid ]; then
98           echo -n "Stopping freeside-prepaidd: "
99           kill `cat /var/run/freeside-prepaidd.pid`
100           echo "done."
101         fi
102
103         if [ -e /var/run/freeside-cdrd.pid ]; then
104           echo -n "Stopping freeside-cdrd: "
105           kill `cat /var/run/freeside-cdrd.pid`
106           echo "done."
107         fi
108
109         if [ -e /var/run/freeside-cdrrewrited.pid ]; then
110           echo -n "Stopping freeside-cdrrewrited: "
111           kill `cat /var/run/freeside-cdrrewrited.pid`
112           echo "done."
113         fi
114
115         if [ -e /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid ]
116         then
117           echo -n "Stopping (old) freeside-selfservice-server: "
118           kill `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid`
119           rm /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid
120           echo "done."
121         fi
122
123         if [ -z "$SELFSERVICE_MACHINES" ]; then SELFSERVICE_MACHINES='localhost'; fi
124         for MACHINE in $SELFSERVICE_MACHINES; do
125           if [ -e /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid ]
126           then
127             echo -n "Stopping freeside-selfservice-server to $MACHINE: "
128             kill `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid`
129             echo "done."
130           fi
131         done
132
133         if [ -e /var/run/freeside/selfservice-xmlrpcd.pid ]; then
134           echo -n "Stopping freeside-selfservice-xmlrpcd: "
135           kill `cat /var/run/freeside/selfservice-xmlrpcd.pid`
136           echo "done."
137         fi
138
139         if [ -e /var/run/freeside/torrus-srvderive.pid ]; then
140           echo -n "Stopping freeside-torrus-srvderive: "
141           kill `cat /var/run/freeside/torrus-srvderive.pid`
142           echo "done."
143         fi
144
145         if [ -e /var/run/torrus/collector.main_?.pid ]; then
146           echo -n "Stopping torrus collector: "
147           kill `cat /var/run/torrus/collector.main_?.pid`
148           echo "done."
149         fi
150
151         ;;
152
153   restart)
154         $0 stop
155         $0 start
156         ;;
157   *)
158         echo "Usage: freeside {start|stop|restart}"
159         exit 1
160 esac
161
162 exit 0
163