rc.suse.asterisk 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/sh
  2. # $Id: asterisk,v 1.3 2005/11/17 22:30:01 Gregory Boehnlein <damin@nacs.net>
  3. #
  4. # asterisk Starts, Stops and Reloads Asterisk.
  5. #
  6. # chkconfig: 2345 40 60
  7. # description: Asterisk PBX and telephony daemon.
  8. # processname: asterisk
  9. # pidfile: /var/run/asterisk.pid
  10. #
  11. # Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
  12. # - Updated Version to 1.3
  13. # - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
  14. # - Added detailed failure messages
  15. #
  16. # Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
  17. # - Updated Version to 1.2
  18. # - Added test for safe_asterisk
  19. # - Verified SIGTERM issued by "killproc" ensures "stop gracefully"
  20. # - Added support for -U and -G command line options
  21. # - Modified "reload" to call asterisk -rx 'reload'
  22. ### BEGIN INIT INFO
  23. # Provides: asterisk
  24. # Required-Start: $network $syslog $named $local_fs $remote_fs
  25. # Required-Stop: $network $syslog $named $local_fs $remote_fs
  26. # Should-Start: dahdi misdn lcr wanrouter mysql postgresql
  27. # Should-Stop: dahdi misdn lcr wanrouter mysql postgresql
  28. # Default-Start: 2 3 4 5
  29. # Default-Stop: 0 1 6
  30. # Short-Description: Asterisk PBX
  31. # Description: the Asterisk Open Source PBX
  32. ### END INIT INFO
  33. # Source function library.
  34. . /lib/lsb/init-functions
  35. if ! [ -x /usr/sbin/asterisk ] ; then
  36. echo "ERROR: /usr/sbin/asterisk not found"
  37. exit 0
  38. fi
  39. if ! [ -d /etc/asterisk ] ; then
  40. echo "ERROR: /etc/asterisk directory not found"
  41. exit 0
  42. fi
  43. # Uncomment this ONLY if you know what you are doing.
  44. # export LD_ASSUME_KERNEL=2.4.1
  45. # Full path to asterisk binary
  46. DAEMON=/usr/sbin/asterisk
  47. # Full path to safe_asterisk script
  48. SAFE_ASTERISK=/usr/sbin/safe_asterisk
  49. # Uncomment the following and set them to the user/groups that you
  50. # want to run Asterisk as. NOTE: this requires substantial work to
  51. # be sure that Asterisk's environment has permission to write the
  52. # files required for its operation, including logs, its comm
  53. # socket, the asterisk database, etc.
  54. #AST_USER="asterisk"
  55. #AST_GROUP="asterisk"
  56. # Allow configuration overrides in /etc/sysconfig/asterisk
  57. CONFIG0=`readlink $0`
  58. if [ "$CONFIG0" = "" ]; then
  59. CONFIGFILE=/etc/sysconfig/`basename $0`
  60. else
  61. CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
  62. fi
  63. [ -r $CONFIGFILE ] && . $CONFIGFILE
  64. RETVAL=0
  65. start() {
  66. # Start daemons.
  67. # Check if Asterisk is already running. If it is, then bug out, because
  68. # starting Asterisk when Asterisk is already running is very bad.
  69. VERSION=`/usr/sbin/asterisk -rx 'core show version' 2>/dev/null`
  70. if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
  71. echo "Asterisk is already running. $0 will exit now."
  72. exit 1
  73. fi
  74. echo -n $"Starting asterisk: "
  75. if [ -f $SAFE_ASTERISK ] ; then
  76. DAEMON=$SAFE_ASTERISK
  77. fi
  78. if [ $AST_USER ] ; then
  79. ASTARGS="-U $AST_USER"
  80. fi
  81. if [ $AST_GROUP ] ; then
  82. ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
  83. fi
  84. if [ $ALTCONF ]; then
  85. ASTARGS="$ASTARGS -C $ALTCONF"
  86. fi
  87. if [ "x$COREDUMP" = "xyes" ]; then
  88. ASTARGS="$ASTARGS -g"
  89. fi
  90. if [ "0$MAXLOAD" -gt "0" ]; then
  91. ASTARGS="$ASTARGS -L $MAXLOAD"
  92. fi
  93. if [ "0$MAXCALLS" -gt "0" ]; then
  94. ASTARGS="$ASTARGS -M $MAXCALLS"
  95. fi
  96. if [ "0$VERBOSITY" -gt "0" ]; then
  97. for i in `seq 1 $VERBOSITY`; do
  98. ASTARGS="$ASTARGS -v"
  99. done
  100. fi
  101. if [ "x$INTERNALTIMING" = "xyes" ]; then
  102. ASTARGS="$ASTARGS -I"
  103. fi
  104. if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
  105. ASTARGS="$ASTARGS -t"
  106. fi
  107. if [ "x$COLOR" = "xyes" ]; then
  108. export TERM=linux
  109. sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 &
  110. else
  111. $DAEMON $ASTARGS
  112. fi
  113. RETVAL=$?
  114. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
  115. echo
  116. return $RETVAL
  117. }
  118. stop() {
  119. # Stop daemons.
  120. echo -n $"Shutting down asterisk: "
  121. killproc asterisk
  122. RETVAL=$?
  123. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
  124. echo
  125. return $RETVAL
  126. }
  127. restart() {
  128. stop
  129. start
  130. }
  131. reload() {
  132. $DAEMON -rx 'module reload' > /dev/null 2> /dev/null
  133. }
  134. # See how we were called.
  135. case "$1" in
  136. start)
  137. start
  138. ;;
  139. stop)
  140. stop
  141. ;;
  142. restart)
  143. restart
  144. ;;
  145. reload)
  146. reload
  147. ;;
  148. condrestart)
  149. [ -f /var/lock/subsys/asterisk ] && restart || :
  150. ;;
  151. status)
  152. status asterisk
  153. ;;
  154. *)
  155. echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
  156. exit 1
  157. esac
  158. exit $?