| 1 |
#!/bin/sh |
| 2 |
# $Id: asterisk,v 1.3 2005/11/17 22:30:01 Gregory Boehnlein <[email protected]> |
| 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 <[email protected]> |
| 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 <[email protected]> |
| 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 |
|
| 23 |
### BEGIN INIT INFO |
| 24 |
# Provides: asterisk |
| 25 |
# Required-Start: $network $syslog $named $local_fs $remote_fs |
| 26 |
# Required-Stop: $network $syslog $named $local_fs $remote_fs |
| 27 |
# Should-Start: dahdi misdn lcr wanrouter mysql postgresql |
| 28 |
# Should-Stop: dahdi misdn lcr wanrouter mysql postgresql |
| 29 |
# Default-Start: 2 3 4 5 |
| 30 |
# Default-Stop: 0 1 6 |
| 31 |
# Short-Description: Asterisk PBX |
| 32 |
# Description: the Asterisk Open Source PBX |
| 33 |
### END INIT INFO |
| 34 |
|
| 35 |
# Source function library. |
| 36 |
. /lib/lsb/init-functions |
| 37 |
|
| 38 |
if ! [ -x /usr/sbin/asterisk ] ; then |
| 39 |
echo "ERROR: /usr/sbin/asterisk not found" |
| 40 |
exit 0 |
| 41 |
fi |
| 42 |
|
| 43 |
if ! [ -d /etc/asterisk ] ; then |
| 44 |
echo "ERROR: /etc/asterisk directory not found" |
| 45 |
exit 0 |
| 46 |
fi |
| 47 |
|
| 48 |
# Uncomment this ONLY if you know what you are doing. |
| 49 |
# export LD_ASSUME_KERNEL=2.4.1 |
| 50 |
|
| 51 |
# Full path to asterisk binary |
| 52 |
DAEMON=/usr/sbin/asterisk |
| 53 |
|
| 54 |
# Full path to safe_asterisk script |
| 55 |
SAFE_ASTERISK=/usr/sbin/safe_asterisk |
| 56 |
|
| 57 |
# Uncomment the following and set them to the user/groups that you |
| 58 |
# want to run Asterisk as. NOTE: this requires substantial work to |
| 59 |
# be sure that Asterisk's environment has permission to write the |
| 60 |
# files required for its operation, including logs, its comm |
| 61 |
# socket, the asterisk database, etc. |
| 62 |
#AST_USER="asterisk" |
| 63 |
#AST_GROUP="asterisk" |
| 64 |
|
| 65 |
# Allow configuration overrides in /etc/sysconfig/asterisk |
| 66 |
CONFIG0=`readlink $0` |
| 67 |
if [ "$CONFIG0" = "" ]; then |
| 68 |
CONFIGFILE=/etc/sysconfig/`basename $0` |
| 69 |
else |
| 70 |
CONFIGFILE=/etc/sysconfig/`basename $CONFIG0` |
| 71 |
fi |
| 72 |
[ -r $CONFIGFILE ] && . $CONFIGFILE |
| 73 |
|
| 74 |
RETVAL=0 |
| 75 |
|
| 76 |
start() { |
| 77 |
# Start daemons. |
| 78 |
|
| 79 |
# Check if Asterisk is already running. If it is, then bug out, because |
| 80 |
# starting Asterisk when Asterisk is already running is very bad. |
| 81 |
VERSION=`/usr/sbin/asterisk -rx 'core show version' 2>/dev/null` |
| 82 |
if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then |
| 83 |
echo "Asterisk is already running. $0 will exit now." |
| 84 |
exit 1 |
| 85 |
fi |
| 86 |
|
| 87 |
echo -n $"Starting asterisk: " |
| 88 |
if [ -f $SAFE_ASTERISK ] ; then |
| 89 |
DAEMON=$SAFE_ASTERISK |
| 90 |
fi |
| 91 |
if [ $AST_USER ] ; then |
| 92 |
ASTARGS="-U $AST_USER" |
| 93 |
fi |
| 94 |
if [ $AST_GROUP ] ; then |
| 95 |
ASTARGS="`echo $ASTARGS` -G $AST_GROUP" |
| 96 |
fi |
| 97 |
if [ $ALTCONF ]; then |
| 98 |
ASTARGS="$ASTARGS -C $ALTCONF" |
| 99 |
fi |
| 100 |
if [ "x$COREDUMP" = "xyes" ]; then |
| 101 |
ASTARGS="$ASTARGS -g" |
| 102 |
fi |
| 103 |
if [ "0$MAXLOAD" -gt "0" ]; then |
| 104 |
ASTARGS="$ASTARGS -L $MAXLOAD" |
| 105 |
fi |
| 106 |
if [ "0$MAXCALLS" -gt "0" ]; then |
| 107 |
ASTARGS="$ASTARGS -M $MAXCALLS" |
| 108 |
fi |
| 109 |
if [ "0$VERBOSITY" -gt "0" ]; then |
| 110 |
for i in `seq 1 $VERBOSITY`; do |
| 111 |
ASTARGS="$ASTARGS -v" |
| 112 |
done |
| 113 |
fi |
| 114 |
if [ "x$INTERNALTIMING" = "xyes" ]; then |
| 115 |
ASTARGS="$ASTARGS -I" |
| 116 |
fi |
| 117 |
if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then |
| 118 |
ASTARGS="$ASTARGS -t" |
| 119 |
fi |
| 120 |
if [ "x$COLOR" = "xyes" ]; then |
| 121 |
export TERM=linux |
| 122 |
sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 & |
| 123 |
else |
| 124 |
$DAEMON $ASTARGS |
| 125 |
fi |
| 126 |
RETVAL=$? |
| 127 |
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk |
| 128 |
echo |
| 129 |
return $RETVAL |
| 130 |
} |
| 131 |
|
| 132 |
stop() { |
| 133 |
# Stop daemons. |
| 134 |
echo -n $"Shutting down asterisk: " |
| 135 |
killproc asterisk |
| 136 |
RETVAL=$? |
| 137 |
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk |
| 138 |
echo |
| 139 |
return $RETVAL |
| 140 |
} |
| 141 |
|
| 142 |
restart() { |
| 143 |
stop |
| 144 |
start |
| 145 |
} |
| 146 |
|
| 147 |
reload() { |
| 148 |
$DAEMON -rx 'module reload' > /dev/null 2> /dev/null |
| 149 |
} |
| 150 |
|
| 151 |
# See how we were called. |
| 152 |
case "$1" in |
| 153 |
start) |
| 154 |
start |
| 155 |
;; |
| 156 |
stop) |
| 157 |
stop |
| 158 |
;; |
| 159 |
restart) |
| 160 |
restart |
| 161 |
;; |
| 162 |
reload) |
| 163 |
reload |
| 164 |
;; |
| 165 |
condrestart) |
| 166 |
[ -f /var/lock/subsys/asterisk ] && restart || : |
| 167 |
;; |
| 168 |
status) |
| 169 |
status asterisk |
| 170 |
;; |
| 171 |
*) |
| 172 |
echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}" |
| 173 |
exit 1 |
| 174 |
esac |
| 175 |
|
| 176 |
exit $? |