summaryrefslogtreecommitdiffstats
path: root/network/asterisk/rc.asterisk.new
blob: 636f4099a083b92ea8e3dd6a590e83158758f228 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
#
# Start/stop/restart Asterisk PBX
#
# Version: 1.0 - Paul Belanger <pabelanger@gmail.com>
#
# 03.29.2005 - Initial Version
#
# $Id$

### BEGIN INIT INFO
# Provides:		asterisk
# Required-Start:    $network $syslog $named $local_fs $remote_fs
# Required-Stop:     $network $syslog $named $local_fs $remote_fs
# Should-Start:      dahdi misdn lcr wanrouter mysql postgresql
# Should-Stop:       dahdi misdn lcr wanrouter mysql postgresql
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Asterisk PBX
# Description:		the Asterisk Open Source PBX
### END INIT INFO

asterisk_start() {
   if [ -x /usr/sbin/asterisk ]; then
      # Check if Asterisk is already running.  If it is, then bug out, because
      # starting safe_asterisk when Asterisk is running is very bad.
      VERSION=`/usr/sbin/asterisk -rx 'core show version' 2>/dev/null`
	  if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
         echo "Asterisk is already running.  $0 will exit now."
         exit 1
      fi

      echo "Starting Asterisk   /usr/sbin/asterisk"
      mkdir -p /var/run/asterisk
      chown @ASTERISKUSR@:@ASTERISKGRP@ /var/run/asterisk
      /usr/sbin/asterisk
   fi
}

asterisk_stop() {
    # If there is no PID file, ignore this request...
    if [ -r /var/run/asterisk/asterisk.pid ]; then
      killall asterisk
    fi
}

asterisk_restart() {
   asterisk_stop
   asterisk_start
}

case "$1" in
   'start')
      asterisk_start
      ;;
   'stop')
      asterisk_stop
      ;;
   'restart')
      asterisk_restart
      ;;
   *)
      echo "usage $0 start|stop|restart" ;;
esac