Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: None | Size: 3.42 KB | Hits: 39 | Expires: Never
Copy text to clipboard
  1. #! /bin/sh
  2. # $Id: rc.debian.asterisk 119301 2008-05-30 16:44:39Z mvanbaak $
  3. #
  4. # Mon Jun 04 2007 IƱaki Baz Castillo <ibc@in.ilimit.es>
  5. # - Eliminated SAFE_ASTERISK since it doesn't work as LSB script (it could require a independent "safe_asterisk" init script).
  6. # - Load and use the standar "/lib/lsb/init-functions".
  7. # - Addded "--oknodo" to "start-stop-daemon" for compatibility with LSB:
  8. #   http://www.linux-foundation.org/spec/refspecs/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
  9. #
  10. # Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
  11. # - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
  12. # - Added detailed failure messages
  13. #
  14. # Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
  15. # - Added test for safe_asterisk
  16. # - Changed "stop gracefully" to "stop now"
  17. # - Added support for -U and -G command line options
  18. # - Modified "reload" to call asterisk -rx 'reload'
  19.  
  20. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  21. NAME=asterisk
  22. DESC="Asterisk PBX"
  23. # Full path to asterisk binary
  24. DAEMON=/usr/sbin/asterisk
  25. STARTDAEMON=/usr/sbin/safe_asterisk
  26. TRUE=/bin/true
  27.  
  28. # Uncomment this ONLY if you know what you are doing.
  29. # export LD_ASSUME_KERNEL=2.4.1
  30.  
  31. # Uncomment the following and set them to the user/groups that you
  32. # want to run Asterisk as. NOTE: this requires substantial work to
  33. # be sure that Asterisk's environment has permission to write the
  34. # files required  for  its  operation, including logs, its comm
  35. # socket, the asterisk database, etc.
  36. #AST_USER="asterisk"
  37. #AST_GROUP="asterisk"
  38.  
  39. set -e
  40.  
  41. if ! [ -x $STARTDAEMON ] ; then
  42.         echo "ERROR: $DAEMON not found"
  43.         exit 0
  44. fi
  45.  
  46. if ! [ -d /etc/asterisk ] ; then
  47.         echo "ERROR: /etc/asterisk directory not found"
  48.         exit 0
  49. fi
  50.  
  51. # Use the LSB standar functions for services management
  52. . /lib/lsb/init-functions
  53.  
  54. case "$1" in
  55.   start)
  56.         # Check if Asterisk is already running.  If it is, then bug out, because
  57.         # starting up Asterisk when Asterisk is already running is very bad.
  58.         VERSION=`${DAEMON} -rx 'core show version' || ${TRUE}`
  59.         if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
  60.                 echo "Asterisk is already running.  $0 will exit now."
  61.                 exit 1
  62.         fi
  63.  
  64.         log_begin_msg "Starting $DESC: $NAME"
  65.         if [ $AST_USER ] ; then
  66.                 ASTARGS="-U $AST_USER"
  67.         fi
  68.         if [ $AST_GROUP ] ; then
  69.                 ASTARGS="$ASTARGS -G $AST_GROUP"
  70.         fi
  71.         # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already running (as LSB expects):
  72.         start-stop-daemon --start --oknodo --exec $STARTDAEMON -- $ASTARGS
  73.         log_end_msg $?
  74.         ;;
  75.   stop)
  76.         log_begin_msg "Stopping $DESC: $NAME"
  77.         # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already stopped (as LSB expects):
  78.         start-stop-daemon --stop --oknodo --exec $STARTDAEMON
  79.         log_end_msg $?
  80.         ;;
  81.   reload)
  82.         echo "Reloading $DESC configuration files."
  83.         $DAEMON -rx 'reload' > /dev/null 2> /dev/null
  84.         ;;
  85.   restart|force-reload)
  86.         $0 stop
  87.         sleep 2  # It needs some time to really be stopped.
  88.         $0 start
  89.         # "restart|force-reload" starts Asterisk and returns 0 even if Asterisk was stopped (as LSB expects).
  90.         ;;
  91.   *)
  92.         N=/etc/init.d/$NAME
  93.         echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  94.         exit 1
  95.         ;;
  96. esac