rc.suse.asterisk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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: +dahdi $network $named
  25. # Required-Stop:
  26. # Default-Start: 3 5
  27. # Default-Stop: 0 1 2 4 6
  28. # Description: dahdi - dahdi modules for Asterisk
  29. ### END INIT INFO
  30. # Source function library.
  31. . /lib/lsb/init-functions
  32. if ! [ -x /usr/sbin/asterisk ] ; then
  33. echo "ERROR: /usr/sbin/asterisk not found"
  34. exit 0
  35. fi
  36. if ! [ -d /etc/asterisk ] ; then
  37. echo "ERROR: /etc/asterisk directory not found"
  38. exit 0
  39. fi
  40. # Uncomment this ONLY if you know what you are doing.
  41. # export LD_ASSUME_KERNEL=2.4.1
  42. # Full path to asterisk binary
  43. DAEMON=/usr/sbin/asterisk
  44. # Full path to safe_asterisk script
  45. SAFE_ASTERISK=/usr/sbin/safe_asterisk
  46. # Uncomment the following and set them to the user/groups that you
  47. # want to run Asterisk as. NOTE: this requires substantial work to
  48. # be sure that Asterisk's environment has permission to write the
  49. # files required for its operation, including logs, its comm
  50. # socket, the asterisk database, etc.
  51. #AST_USER="asterisk"
  52. #AST_GROUP="asterisk"
  53. RETVAL=0
  54. start() {
  55. # Start daemons.
  56. # Check if Asterisk is already running. If it is, then bug out, because
  57. # starting Asterisk when Asterisk is already running is very bad.
  58. VERSION=`/usr/sbin/asterisk -rx 'core show version'`
  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. echo -n $"Starting asterisk: "
  64. if [ -f $SAFE_ASTERISK ] ; then
  65. DAEMON=$SAFE_ASTERISK
  66. fi
  67. if [ $AST_USER ] ; then
  68. ASTARGS="-U $AST_USER"
  69. fi
  70. if [ $AST_GROUP ] ; then
  71. ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
  72. fi
  73. $DAEMON $ASTARGS
  74. RETVAL=$?
  75. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
  76. echo
  77. return $RETVAL
  78. }
  79. stop() {
  80. # Stop daemons.
  81. echo -n $"Shutting down asterisk: "
  82. killproc asterisk
  83. RETVAL=$?
  84. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
  85. echo
  86. return $RETVAL
  87. }
  88. restart() {
  89. stop
  90. start
  91. }
  92. reload() {
  93. $DAEMON -rx 'reload' > /dev/null 2> /dev/null
  94. }
  95. # See how we were called.
  96. case "$1" in
  97. start)
  98. start
  99. ;;
  100. stop)
  101. stop
  102. ;;
  103. restart)
  104. restart
  105. ;;
  106. reload)
  107. reload
  108. ;;
  109. condrestart)
  110. [ -f /var/lock/subsys/asterisk ] && restart || :
  111. ;;
  112. status)
  113. status asterisk
  114. ;;
  115. *)
  116. echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
  117. exit 1
  118. esac
  119. exit $?