rc.redhat.asterisk 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/bin/sh
  2. # $Id$
  3. #
  4. # asterisk Starts, Stops and Reloads Asterisk.
  5. #
  6. # chkconfig: 2345 90 60
  7. # description: Asterisk PBX and telephony daemon.
  8. # processname: asterisk
  9. # pidfile: __ASTERISK_VARRUN_DIR__/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. # Use this option to specify a different configuration directory
  34. #AST_CONFIG=__ASTERISK_ETC_DIR__
  35. # Installation directory
  36. AST_SBIN=__ASTERISK_SBIN_DIR__
  37. # Source function library.
  38. . /etc/rc.d/init.d/functions
  39. if ! [ -x $AST_SBIN/asterisk ] ; then
  40. echo "ERROR: $AST_SBIN/asterisk not found"
  41. exit 0
  42. fi
  43. if ! [ -d $AST_CONFIG ] ; then
  44. echo "ERROR: $AST_CONFIG directory not found"
  45. exit 0
  46. fi
  47. # Full path to asterisk binary
  48. DAEMON=$AST_SBIN/asterisk
  49. # Full path to safe_asterisk script
  50. SAFE_ASTERISK=$AST_SBIN/safe_asterisk
  51. # Allow configuration overrides in /etc/sysconfig/asterisk
  52. CONFIG0=`readlink $0`
  53. if [ "$CONFIG0" = "" ]; then
  54. CONFIGFILE=/etc/sysconfig/`basename $0`
  55. else
  56. CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
  57. fi
  58. [ -r $CONFIGFILE ] && . $CONFIGFILE
  59. RETVAL=0
  60. start() {
  61. # Check if Asterisk is already running. If it is, then bug out, because
  62. # starting safe_asterisk when Asterisk is running is very bad.
  63. VERSION=`${AST_SBIN}/asterisk -rx 'core show version' 2>/dev/null`
  64. if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
  65. echo "Asterisk is already running."
  66. exit 0
  67. fi
  68. # Start daemons.
  69. echo -n $"Starting asterisk: "
  70. if [ -f $SAFE_ASTERISK ] ; then
  71. DAEMON=$SAFE_ASTERISK
  72. fi
  73. if [ $AST_USER ] ; then
  74. ASTARGS="-U $AST_USER"
  75. fi
  76. if [ $AST_GROUP ] ; then
  77. ASTARGS="$ASTARGS -G $AST_GROUP"
  78. fi
  79. if [ $AST_CONFIG ]; then
  80. ASTARGS="$ASTARGS -C $AST_CONFIG/asterisk.conf"
  81. elif [ $ALTCONF ]; then
  82. ASTARGS="$ASTARGS -C $ALTCONF"
  83. fi
  84. if [ "x$COREDUMP" = "xyes" ]; then
  85. ASTARGS="$ASTARGS -g"
  86. fi
  87. if [ "0$MAXLOAD" -gt "0" ]; then
  88. ASTARGS="$ASTARGS -L $MAXLOAD"
  89. fi
  90. if [ "0$MAXCALLS" -gt "0" ]; then
  91. ASTARGS="$ASTARGS -M $MAXCALLS"
  92. fi
  93. if [ "0$VERBOSITY" -gt "0" ]; then
  94. for i in `seq 1 $VERBOSITY`; do
  95. ASTARGS="$ASTARGS -v"
  96. done
  97. fi
  98. if [ "x$INTERNALTIMING" = "xyes" ]; then
  99. ASTARGS="$ASTARGS -I"
  100. fi
  101. if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
  102. ASTARGS="$ASTARGS -t"
  103. fi
  104. if [ "x$COLOR" = "xyes" ]; then
  105. export TERM=linux
  106. daemon sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 &
  107. else
  108. daemon $DAEMON $ASTARGS
  109. fi
  110. RETVAL=$?
  111. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
  112. echo
  113. return $RETVAL
  114. }
  115. stop() {
  116. # Stop daemons.
  117. if [ -f $SAFE_ASTERISK ]; then
  118. # Kill safe_asterisk first, to prevent us from starting up 2 instances of safe_asterisk
  119. echo -n $"Stopping safe_asterisk: "
  120. killproc `basename $SAFE_ASTERISK`
  121. echo
  122. fi
  123. echo -n $"Shutting down asterisk: "
  124. killproc `basename $DAEMON`
  125. RETVAL=$?
  126. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
  127. echo
  128. return $RETVAL
  129. }
  130. restart() {
  131. stop
  132. start
  133. }
  134. reload() {
  135. $DAEMON -rx 'module reload' > /dev/null 2> /dev/null
  136. }
  137. # See how we were called.
  138. case "$1" in
  139. start)
  140. start
  141. ;;
  142. stop)
  143. stop
  144. ;;
  145. restart)
  146. restart
  147. ;;
  148. reload)
  149. reload
  150. ;;
  151. condrestart)
  152. [ -f /var/lock/subsys/asterisk ] && restart || :
  153. ;;
  154. status)
  155. status asterisk
  156. ;;
  157. *)
  158. echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
  159. exit 1
  160. esac
  161. exit $?