Asterisk start/stop script for (open)SuSE Linux


Due to the rather big response I got from the Asterisk-Users List after my post about the script I modified for  SuSE Linux to start/stop Asterisk automatically, I decided to publish it  instead of emailing it everytime I was asked for it :-)

Please notice: I posted this script back in 2004 and haven’t used Asterisk PBX on openSUSE much since then so I trust it will still work on your system with no or minor modifications.

The Script:

 # asterisk       This shell script takes care of starting and stopping Asterisk.
 # 08.Sept.2004 - Modified to be used on a SuSE Linux system by Martin Mielke.
 #                Please, send your comments/flames/salary increases/geek t-shirts, etc
 #		   to <martin at mielke dot com>
 # Source function library.
 # Shell functions sourced from /etc/rc.status:
 #      rc_check         check and set local and overall rc status
 #      rc_status        check and set local and overall rc status
 #      rc_status -v     ditto but be verbose in local rc status
 #      rc_status -v -r  ditto and clear the local rc status
 #      rc_failed        set local and overall rc status to failed
 #      rc_failed <num>  set local and overall rc status to <num><num>
 #      rc_reset         clear local rc status (overall remains)
 #      rc_exit          exit appropriate to overall rc status
 . /etc/rc.status 

 ASTERISK_OPTS="-nqg"	# -n: Disable console colorization
 # -q: Quiet mode (supress output)
 # -g: Dump core in case of a crash 

 [ -f $ASTERISK_BIN ] || exit 0 


 # See how we were called.
 case "$1" in
 # Start daemons.
 echo -n "Starting Asterisk PBX: "
 [ $RETVAL -eq 0 ] && touch $ASTERISK_LOCK
 rc_status -v
 # Stop daemons.
 echo -n "Shutting down Asterisk PBX: "
 killproc asterisk
 rc_status -v
 [ $RETVAL -eq 0 ] && rm -f $ASTERISK_LOCK
 echo -n "Checking for service Asterisk PBX: "
 /sbin/checkproc -p $ASTERISK_PID $ASTERISK_BIN
 rc_status -v
 $0 stop
 $0 start
 rc_status -v
 echo "Usage: asterisk {start|stop|restart|reload|status}"
 exit 1

 exit $RETVAL

How to install:

Although I assume you already know how to install such an script on your system, I got some emails from people without much experience with Linux, so I hope they’ll find this info of some use… :-)

Proceed as follows:

Become root:

$ su -l

Password: [your-root-passwd-here]

Save the script as /etc/init.d/asterisk

Make a symbolic link from /etc/init.d/rc3.d to it for Asterisk to start on system boot

# cd /etc/init.d/rc3.d

# ln -s ../asterisk S90asterisk

Make a symbolic link from /etc/init.d/rc0.d to it for Asterisk to stop on system shutdown

# cd /etc/init.d/rc0.d

# ln -s ../asterisk K10asterisk

How to use:

Once installed, if you wish to start/stop Asterisk manually, become root and type:

/etc/init.d/asterisk  [your-option]

where ‘your-option’ can be one of the following:

start: To start the Asterisk PBX

stop: To stop the Asterisk PBX

status: To check the status of the Asterisk PBX

restart: To restart the Asterisk PBX


This script is provided to the Asterisk PBX Community on an “AS IS” basis. The author is not to be held responsible for any damages it might cause due to its use.

Please contact me if you feel this script needs updating.