aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/init.d/rc.archlinux.asterisk
blob: fec62af983bf46361bc268335573642cbd4c2d37 (plain)
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
#!/bin/bash
#
# Start/stop/restart Asterisk PBX
#
# Version: 0.1 by Sherif Nagy AKA DarKnesS_WolF <sherif.nagy@gmail.com> BASED ON THE SLACKWARE INIT SCRIPT
#
# 10.10.2008 - Initial Version
#
. /etc/rc.conf
. /etc/rc.d/functions
DAEMON=__ASTERISK_SBIN_DIR__/asterisk
ASTVARRUNDIR=__ASTERISK_VARRUN_DIR__

case "$1" in
  start)
    stat_busy "Starting Asterisk..."
	if [ ! -d $ASTVARRUNDIR ]; then
		mkdir -p $ASTVARRUNDIR
	fi
    if [ -x $DAEMON ]; 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=`${DAEMON} -rx 'core show version'`
      if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
         echo "Asterisk is already running.  $0 will exit now."
         exit 1
      fi
	  ${DAEMON}
      stat_done
    fi
    ;;
  stop)
    if [ -r ${ASTVARRUNDIR}/asterisk.pid ]; then
      stat_busy "Stoping Asterisk..."
      ${DAEMON} -rx "core stop now" > /dev/null 2&>1
      if [ $? -gt 0 ]; then
        stat_fail
      else
        stat_done
      fi
    fi
    ;;
  restart)
    $0 stop
    sleep 2
    $0 start
    ;;
  *)
    echo "usage $0 start|stop|restart" ;;
esac
exit 0