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