From Alex, 7 Years ago, written in Bash.
- view diff
Embed
  1.  
  2. #!/bin/bash
  3. #
  4. #       /etc/rc.d/init.d/freeswitch
  5. #
  6. #       The FreeSwitch Open Source Voice Platform
  7. #
  8. #  chkconfig: 345 89 14
  9. #  description: Starts and stops the freeswitch server daemon
  10. #  processname: freeswitch
  11. #  config: /usr/local/freeswitch/conf/freeswitch.conf
  12. #  pidfile: /usr/local/freeswitch/run/freeswitch.pid
  13. #
  14.  
  15. # Source function library.
  16. . /etc/init.d/functions
  17.  
  18. PROG_NAME=freeswitch
  19. PID_FILE=${PID_FILE-/usr/local/freeswitch/log/freeswitch.pid}
  20. FS_USER=${FS_USER-freeswitch}
  21. FS_FILE=${FS_FILE-/usr/local/freeswitch/bin/freeswitch}
  22. FS_HOME=${FS_HOME-/usr/local/freeswitch}
  23. LOCK_FILE=/var/lock/subsys/freeswitch
  24. FREESWITCH_ARGS="-nc"
  25. RETVAL=0
  26.  
  27. # Source usr/localions file
  28. if [ -f /etc/sysconfig/freeswitch ]; then
  29.         . /etc/sysconfig/freeswitch
  30. fi
  31.  
  32. # <define any local shell functions used by the code that follows>
  33.  
  34. start() {
  35.         echo -n "Starting $PROG_NAME: "
  36.         if [ -e $LOCK_FILE ]; then
  37.             if [ -e $PID_FILE ] && [ -e /proc/`cat $PID_FILE` ]; then
  38.                 echo
  39.                 echo -n $"$PROG_NAME is already running.";
  40.                 failure $"$PROG_NAME is already running.";
  41.                 echo
  42.                 return 1
  43.             fi
  44.         fi
  45.         cd $FS_HOME
  46.         daemon --user $FS_USER --pidfile $PID_FILE "$FS_FILE $FREESWITCH_ARGS $FREESWITCH_PARAMS >/dev/null 2>&1"
  47.                 RETVAL=$?
  48.                 echo
  49.         [ $RETVAL -eq 0 ] && touch $LOCK_FILE;
  50.         echo
  51.         return $RETVAL
  52. }
  53.  
  54. stop() {
  55.         echo -n "Shutting down $PROG_NAME: "
  56.         if [ ! -e $LOCK_FILE ]; then
  57.             echo
  58.             echo -n $"cannot stop $PROG_NAME: $PROG_NAME is not running."
  59.             failure $"cannot stop $PROG_NAME: $PROG_NAME is not running."
  60.             echo
  61.             return 1;
  62.         fi
  63.         cd $FS_HOME
  64.         $FS_FILE -stop > /dev/null 2>&1
  65.         killproc $PROG_NAME
  66.         RETVAL=$?
  67.         echo
  68.         [ $RETVAL -eq 0 ] &&  rm -f $LOCK_FILE;
  69.         return $RETVAL
  70. }
  71.  
  72. rhstatus() {
  73.         status $PROG_NAME;
  74. }
  75.  
  76. case "$1" in
  77.     start)
  78.         start
  79.         ;;
  80.     stop)
  81.         stop
  82.         ;;
  83.     status)
  84.         status $PROG_NAME
  85.         RETVAL=$?
  86.         ;;
  87.     restart)
  88.         stop
  89.         start
  90.         ;;
  91.     reload)
  92. #        <cause the service configuration to be reread, either with
  93. #        kill -HUP or by restarting the daemons, in a manner similar
  94. #        to restart above>
  95.         ;;
  96.     condrestart)
  97.         [ -f $PID_FILE ] && restart || :
  98.         ;;
  99.     *)
  100.         echo "Usage: $PROG_NAME {start|stop|status|reload|restart}"
  101.         exit 1
  102.         ;;
  103. esac
  104. exit $RETVAL