5.3. Starting and Stopping Asterisk

What is the best way to stop and start Asterisk? Does it need to be restarted when you change configuration files, or can you reload changes without disrupting service?

There are several ways to stop and start Asterisk, depending on what you want to do. You'll have two different command interfaces to use: the Linux command line, and the Asterisk command console. You should use the Asterisk console to control Asterisk.

After installing Asterisk, first reboot the system, then check to see if it is running with ps:

	$ ps ax | grep asterisk

It should be, if you ran the make config command during installation, because this creates the files necessary to start up automatically at boot.

Then, all you do is attach to the running Asterisk server and open the console with this command:

	[root@asterisk1 ~]# asterisk -rvvv
	Asterisk 1.4.4, Copyright (C) 1999 - 2007 Digium, Inc. and others.
	Created by Mark Spencer <markster@digium.com>
	Asterisk comes with ABSOLUTELY NO WARRANTY; type 'show warranty' for details.
	This is free software, with components licensed under the GNU General Public
	License version 2 and other licenses; you are welcome to redistribute it under
	certain conditions. Type 'show license' for details.
	=========================================================================
	  == Parsing '/etc/asterisk/asterisk.conf': Found
	  == Parsing '/etc/asterisk/extconfig.conf': Found
	Connected to Asterisk 1.4.4 currently running on asterisk1 (pid = 31461)
	Verbosity was 0 and is now 3

	You can exit from the Asterisk console and return to the Linux Bash shell with the
	quit or exit commands.

	Type help to see a list of Asterisk commands. The list is probably too long for your
	screen, so page up and down by holding down the Shift key and pressing Page Up/Page
	Down.

	Type help [commandname] to get information on specific commands:

	asterisk1*CLI> help stop gracefully
	Usage: stop gracefully
	       Causes Asterisk to not accept new calls, and exit when all
	       active calls have terminated normally.

Asterisk installs with the usual startup files, and is controlled from the Linux command line with these commands:

	# /etc/init.d/asterisk start
	# /etc/init.d/asterisk restart
	# /etc/init.d/asterisk stop
	# /etc/init.d/asterisk status

These are all right to use in testing, but they disrupt service so they're not appropriate for a production system. Use the Asterisk console commands to reload changes in the following configuration files without interrupting active calls:

The exclamation point is used to execute external Linux commands from the Asterisk console. You can also open a Linux shell inside the Asterisk console:

	*CLI> !
	[root@asterisk1 ~]#

Type exit to return to Asterisk.

There are several ways to shutdown Asterisk:

Making and loading configuration changes on a running server with a minimum of disruption is one of Asterisk's nicer features, as cutting off callers in mid-stream won't win you any friends. However, on a busy system, you might find yourself waiting a long time for a graceful shutdown, so stop now is a useful option.

If you don't have startup files for Asterisk, or don't want it to start at boot, use this command to start up the Asterisk server:

	# asterisk -cvvv