rc.debian.asterisk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #! /bin/sh
  2. # $Id$
  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. # - Added "--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. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  20. NAME=asterisk
  21. DESC="Asterisk PBX"
  22. # Full path to asterisk binary
  23. DAEMON=__ASTERISK_SBIN_DIR__/asterisk
  24. ASTVARRUNDIR=__ASTERISK_VARRUN_DIR__
  25. ASTETCDIR=__ASTERISK_ETC_DIR__
  26. TRUE=/bin/true
  27. ### BEGIN INIT INFO
  28. # Provides: asterisk
  29. # Required-Start: $network $syslog $named $local_fs $remote_fs
  30. # Required-Stop: $network $syslog $named $local_fs $remote_fs
  31. # Should-Start: dahdi misdn lcr wanrouter mysql postgresql
  32. # Should-Stop: dahdi misdn lcr wanrouter mysql postgresql
  33. # Default-Start: 2 3 4 5
  34. # Default-Stop: 0 1 6
  35. # Short-Description: Asterisk PBX
  36. # Description: the Asterisk Open Source PBX
  37. ### END INIT INFO
  38. set -e
  39. if ! [ -x $DAEMON ] ; then
  40. echo "ERROR: $DAEMON not found"
  41. exit 0
  42. fi
  43. if ! [ -d $ASTETCDIR ] ; then
  44. echo "ERROR: $ASTETCDIR directory not found"
  45. exit 0
  46. fi
  47. # Use the LSB standard functions for services management
  48. . /lib/lsb/init-functions
  49. # Allow configuration overrides in /etc/default/asterisk
  50. CONFIG0=`readlink $0 || :` # readlink returns 1 when something isn't a symlink
  51. if [ "$CONFIG0" = "" ]; then
  52. CONFIGFILE=/etc/default/`basename $0`
  53. else
  54. CONFIGFILE=/etc/default/`basename $CONFIG0`
  55. fi
  56. [ -r $CONFIGFILE ] && . $CONFIGFILE
  57. case "$1" in
  58. start)
  59. # Check if Asterisk is already running. If it is, then bug out, because
  60. # starting up Asterisk when Asterisk is already running is very bad.
  61. VERSION=`${DAEMON} -rx 'core show version' 2>/dev/null || ${TRUE}`
  62. if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
  63. echo "Asterisk is already running. $0 will exit now."
  64. exit 0
  65. fi
  66. log_begin_msg "Starting $DESC: $NAME"
  67. if [ ! -d $ASTVARRUNDIR ]; then
  68. mkdir -p $ASTVARRUNDIR
  69. fi
  70. if [ $AST_USER ] ; then
  71. ASTARGS="-U $AST_USER"
  72. chown $AST_USER $ASTVARRUNDIR
  73. fi
  74. if [ $AST_GROUP ] ; then
  75. ASTARGS="$ASTARGS -G $AST_GROUP"
  76. chgrp $AST_GROUP $ASTVARRUNDIR
  77. fi
  78. if [ $ALTCONF ]; then
  79. ASTARGS="$ASTARGS -C \"$ALTCONF\""
  80. fi
  81. if [ "x$COREDUMP" = "xyes" ]; then
  82. ASTARGS="$ASTARGS -g"
  83. fi
  84. if [ "0$MAXLOAD" -gt "0" ]; then
  85. ASTARGS="$ASTARGS -L $MAXLOAD"
  86. fi
  87. if [ "0$MAXCALLS" -gt "0" ]; then
  88. ASTARGS="$ASTARGS -M $MAXCALLS"
  89. fi
  90. if [ "0$VERBOSITY" -gt "0" ]; then
  91. for i in `seq 1 $VERBOSITY`; do
  92. ASTARGS="$ASTARGS -v"
  93. done
  94. # -v implies -f, so we override that implicit specification here
  95. ASTARGS="$ASTARGS -F"
  96. fi
  97. if [ "x$INTERNALTIMING" = "xyes" ]; then
  98. ASTARGS="$ASTARGS -I"
  99. fi
  100. if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
  101. ASTARGS="$ASTARGS -t"
  102. fi
  103. if test "x$COLOR" = "xno" ; then
  104. ASTARGS="$ASTARGS -n"
  105. fi
  106. # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already running (as LSB expects):
  107. start-stop-daemon --start --oknodo --exec $DAEMON -- $ASTARGS
  108. log_end_msg $?
  109. ;;
  110. stop)
  111. log_begin_msg "Stopping $DESC: $NAME"
  112. # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already stopped (as LSB expects):
  113. start-stop-daemon --stop --oknodo --exec $DAEMON
  114. log_end_msg $?
  115. ;;
  116. reload)
  117. echo "Reloading $DESC configuration files."
  118. $DAEMON -rx 'module reload' > /dev/null 2> /dev/null
  119. ;;
  120. restart|force-reload)
  121. $0 stop
  122. sleep 2 # It needs some time to really be stopped.
  123. $0 start
  124. # "restart|force-reload" starts Asterisk and returns 0 even if Asterisk was stopped (as LSB expects).
  125. ;;
  126. status)
  127. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  128. ;;
  129. *)
  130. N=/etc/init.d/$NAME
  131. echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
  132. exit 1
  133. ;;
  134. esac