RT# 83450 - added fields interface and map_location to export
[freeside.git] / init.d / freeside-init
index 68cba8d..a7bb3d1 100644 (file)
-#! /bin/sh
+#!/bin/sh
 #
 # chkconfig: 345 86 16
 # description: Freeside daemons
+#
+### BEGIN INIT INFO
+# Provides:          freeside
+# Required-Start:    $time $remote_fs
+# Required-Stop:     $remote_fs
+# Should-Start:      postgresql mysql
+# Should-Stop:       postgresql mysql
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start Freeside daemons at boot time
+# Description:       Enable Freeside daemons
+### END INIT INFO
 
 QUEUED_USER=%%%QUEUED_USER%%%
+API_USER=%%%API_USER%%%
 
-FREESIDE_PATH="%%%FREESIDE_PATH%%%"
+SELFSERVICE_USER=%%%SELFSERVICE_USER%%%
+SELFSERVICE_MACHINES="%%%SELFSERVICE_MACHINES%%%"
 
-PASSWD_USER=%%%PASSWD_USER%%%
-PASSWD_MACHINE=%%%PASSWD_MACHINE%%%
+IF=eth0
 
-SIGNUP_USER=%%%SIGNUP_USER%%%
-SIGNUP_MACHINE=%%%SIGNUP_MACHINE%%%
-SIGNUP_AGENTNUM=%%%SIGNUP_AGENTNUM%%%
-SIGNUP_REFNUM=%%%SIGNUP_REFNUM%%%
+#INSTALLSCRIPT/INSTALLSITEBIN from Makefile.PL
+PATH="$PATH:/usr/local/bin"
+export PATH
 
-SELFSERVICE_USER=%%%SELFSERVICE_USER%%%
-SELFSERVICE_MACHINE=%%%SELFSERVICE_MACHINE%%%
+[ -r /etc/default/freeside ] && . /etc/default/freeside
 
 case "$1" in
   start)
         # Start daemons.
+
+        for MACHINE in $SELFSERVICE_MACHINES; do
+          echo -n "Starting freeside-selfservice-server to $MACHINE: "
+          freeside-selfservice-server $SELFSERVICE_USER $MACHINE
+          echo "done."
+        done
+
+        echo -n "Starting freeside-selfservice-xmlrpcd: "
+        freeside-selfservice-xmlrpcd $SELFSERVICE_USER
+        echo "done."
+
+        echo -n "Starting freeside-xmlrpcd: "
+        freeside-xmlrpcd $API_USER
+        echo "done."
+
+#        echo -n "Starting freeside-jsonrpcd: "
+#        freeside-jsonrpcd $API_USER
+#        echo "done."
+
         echo -n "Starting freeside-queued: "
+        #perl -MDBIx::Profile /usr/local/bin/freeside-queued $QUEUED_USER
         freeside-queued $QUEUED_USER
+        #export NYTPROF="file=/usr/local/etc/freeside/nytprof.out"
+        #PERL5OPT="-d:NYTProf" freeside-queued $QUEUED_USER
         echo "done."
 
-        echo -n "Starting fs_passwd_server: "
-        su freeside -c "$FREESIDE_PATH/fs_passwd/fs_passwd_server $PASSWD_USER $PASSWD_MACHINE" &
+        echo -n "Starting freeside-sqlradius-radacctd: "
+        freeside-sqlradius-radacctd $QUEUED_USER
         echo "done."
 
-        echo -n "Starting fs_signup_server: "
-        su freeside -c "$FREESIDE_PATH/fs_signup/fs_signup_server $SIGNUP_USER $SIGNUP_MACHINE $SIGNUP_AGENTNUM $SIGNUP_REFNUM" &
+        echo -n "Starting freeside-prepaidd: "
+        freeside-prepaidd $QUEUED_USER
         echo "done."
 
-        echo -n "Starting freeside-selfservice-server: "
-        freeside-selfservice-server $SELFSERVICE_USER $SELFSERVICE_MACHINE
+        echo -n "Starting freeside-cdrrewrited: "
+        freeside-cdrrewrited $QUEUED_USER
         echo "done."
 
-        ;;
-  stop)
-        # Stop daemons.
-        echo -n "Stopping freeside-queued: "
-        kill `cat /var/run/freeside-queued.pid`
+        echo -n "Starting freeside-cdrd: "
+        freeside-cdrd $QUEUED_USER
+        echo "done."
+
+        echo -n "Starting freeside-cdrrated: "
+        freeside-cdrrated $QUEUED_USER
         echo "done."
 
-        echo -n "Stopping fs_passwd_server: "
-        killall fs_passwd_server
+        echo -n "Starting freeside-pingd: "
+        freeside-pingd $QUEUED_USER
         echo "done."
 
-        echo -n "Stopping fs_signup_server: "
-        killall fs_signup_server
+        if [ -e /usr/local/bin/torrus ]; then
+          echo -n "Starting torrus collector: "
+          /usr/local/bin/torrus collector --tree=main
+          echo "done."
+        fi
+
+        echo -n "Starting freeside-torrus-srvderive: "
+        freeside-torrus-srvderive $QUEUED_USER
         echo "done."
 
-        echo -n "Stopping freeside-selfservice-server: "
-        kill `cat /var/run/freeside-selfservice-server.pid`
+        if [ -e /opt/rt3/etc/RT_SiteConfig.pm.ORIG_WEBDEMO_HACK ]; then
+          ip=`/sbin/ifconfig $IF | grep 'inet addr:' | cut -d: -f2- | cut -d' ' -f1`
+          cp /opt/rt3/etc/RT_SiteConfig.pm.ORIG_WEBDEMO_HACK /opt/rt3/etc/RT_SiteConfig.pm
+          perl -pi -e "s/localhost/$ip/" /opt/rt3/etc/RT_SiteConfig.pm
+        fi
+
+        ;;
+  stop)
+        # Stop daemons.
+        echo -n "Stopping freeside-queued: "
+        [ -e /var/run/freeside-queued.pid ] && kill `cat /var/run/freeside-queued.pid`
+        #and
+        sleep 2;
+        killall freeside-queued
         echo "done."
+
+        if [ -e /var/run/freeside-sqlradius-radacctd.pid ]; then
+          echo -n "Stopping freeside-sqlradius-radacctd: "
+          kill `cat /var/run/freeside-sqlradius-radacctd.pid`
+          echo "done."
+        fi
+
+        if [ -e /var/run/freeside-prepaidd.pid ]; then
+          echo -n "Stopping freeside-prepaidd: "
+          kill `cat /var/run/freeside-prepaidd.pid`
+          echo "done."
+        fi
+
+        if [ -e /var/run/freeside-cdrd.pid ]; then
+          echo -n "Stopping freeside-cdrd: "
+          kill `cat /var/run/freeside-cdrd.pid`
+          echo "done."
+        fi
+
+        if [ -e /var/run/freeside-cdrrewrited.pid ]; then
+          echo -n "Stopping freeside-cdrrewrited: "
+          kill `cat /var/run/freeside-cdrrewrited.pid`
+          echo "done."
+        fi
+
+        if [ -e /var/run/freeside-cdrrated.pid ]; then
+          echo -n "Stopping freeside-cdrrated: "
+          kill `cat /var/run/freeside-cdrrated.pid`
+          echo "done."
+        fi
+
+        if [ -e /var/run/freeside-pingd.pid ]; then
+          echo -n "Stopping freeside-pingd: "
+          kill `cat /var/run/freeside-pingd.pid`
+          echo "done."
+        fi
+
+        if [ -e /var/run/freeside/torrus-srvderive.pid ]; then
+          echo -n "Stopping freeside-torrus-srvderive: "
+          kill `cat /var/run/freeside/torrus-srvderive.pid`
+          echo "done."
+        fi
+
+        if [ -e /var/run/torrus/collector.main_?.pid ]; then
+          echo -n "Stopping torrus collector: "
+          kill `cat /var/run/torrus/collector.main_?.pid`
+          echo "done."
+        fi
+
+        if [ -e /var/run/freeside/xmlrpcd.pid ]; then
+          echo -n "Stopping freeside-xmlrpcd: "
+          kill `cat /var/run/freeside/xmlrpcd.pid`
+          echo "done."
+        fi
+
+#        if [ -e /var/run/freeside/jsonrpcd.pid ]; then
+#          echo -n "Stopping freeside-jsonrpcd: "
+#          kill `cat /var/run/freeside/jsonrpcd.pid`
+#          echo "done."
+#        fi
+
+        if [ -e /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid ]
+        then
+          echo -n "Stopping (old) freeside-selfservice-server: "
+          kill `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid`
+          sleep 
+          rm /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid
+          echo "done."
+        fi
+
+        if [ -z "$SELFSERVICE_MACHINES" ]; then SELFSERVICE_MACHINES='localhost'; fi
+        for MACHINE in $SELFSERVICE_MACHINES; do
+          if [ -e /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid ]
+          then
+            echo -n "Stopping freeside-selfservice-server to $MACHINE"
+            kill `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid`
+            howlong=10
+            while [ $howlong -gt 0 ] && kill -0 `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid` 2>/dev/null; do
+              echo -n '.'
+              sleep 1
+              howlong=$(( $howlong - 1 ))
+              if [ $howlong -eq 0 ]; then
+                echo -n 'forcefully.'
+                kill -9 `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid`
+              fi
+            done
+            echo "done."
+            rm /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid
+          fi
+        done
+
+        if [ -e /var/run/freeside/selfservice-xmlrpcd.pid ]; then
+          echo -n "Stopping freeside-selfservice-xmlrpcd: "
+          kill `cat /var/run/freeside/selfservice-xmlrpcd.pid`
+          echo "done."
+        fi
+
         ;;
 
   restart)