rc.archlinux.asterisk 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. #
  3. # Start/stop/restart Asterisk PBX
  4. #
  5. # Version: 0.1 by Sherif Nagy AKA DarKnesS_WolF <sherif.nagy@gmail.com> BASED ON THE SLACKWARE INIT SCRIPT
  6. #
  7. # 10.10.2008 - Initial Version
  8. #
  9. ### BEGIN INIT INFO
  10. # Provides: asterisk
  11. # Required-Start: $network $syslog $named $local_fs $remote_fs
  12. # Required-Stop: $network $syslog $named $local_fs $remote_fs
  13. # Should-Start: dahdi misdn lcr wanrouter mysql postgresql
  14. # Should-Stop: dahdi misdn lcr wanrouter mysql postgresql
  15. # Default-Start: 2 3 4 5
  16. # Default-Stop: 0 1 6
  17. # Short-Description: Asterisk PBX
  18. # Description: the Asterisk Open Source PBX
  19. ### END INIT INFO
  20. . /etc/rc.conf
  21. . /etc/rc.d/functions
  22. DAEMON=__ASTERISK_SBIN_DIR__/asterisk
  23. ASTVARRUNDIR=__ASTERISK_VARRUN_DIR__
  24. case "$1" in
  25. start)
  26. stat_busy "Starting Asterisk..."
  27. if [ ! -d $ASTVARRUNDIR ]; then
  28. mkdir -p $ASTVARRUNDIR
  29. fi
  30. if [ -x $DAEMON ]; then
  31. # Check if Asterisk is already running. If it is, then bug out, because
  32. # starting safe_asterisk when Asterisk is running is very bad.
  33. VERSION=`${DAEMON} -rx 'core show version' 2>/dev/null`
  34. if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
  35. echo "Asterisk is already running. $0 will exit now."
  36. exit 1
  37. fi
  38. ${DAEMON}
  39. stat_done
  40. fi
  41. ;;
  42. stop)
  43. if [ -r ${ASTVARRUNDIR}/asterisk.pid ]; then
  44. stat_busy "Stopping Asterisk..."
  45. ${DAEMON} -rx "core stop now" > /dev/null 2&>1
  46. if [ $? -gt 0 ]; then
  47. stat_fail
  48. else
  49. stat_done
  50. fi
  51. fi
  52. ;;
  53. restart)
  54. $0 stop
  55. sleep 2
  56. $0 start
  57. ;;
  58. *)
  59. echo "usage $0 start|stop|restart" ;;
  60. esac
  61. exit 0