Starting and Stopping the Asterisk Server

News Asterisk The Open Source PBX Recommended Links Reloading Starting Stopping
Asterisk CLI Troubleshooting     Humor Etc

The Asterisk program has two modes of operation: server mode and client mode. The server is the instance of Asterisk that stays running all the time, handling calls, recording voicemails, greeting callers while users are away, and so on. The client is the instance of Asterisk that allows you to monitor and manipulate the server while it runs. The mode the program uses depends on how Asterisk is invoked at the command prompt or within a shell script.

Reloading

To reload from command line on Linux use service asterisk reload.

One very useful ability of the console is to issue a reload. This is done by:

CLI> reload  

This command will re-parse the configuration files and update the changes in most of the modules of Asterisk.

To launch Asterisk in server mode, execute this command:

	# asterisk -vvv &

The more v's, the more verbose Asterisk's console output will be.

To connect Asterisk in client mode on the local machine already running in server mode, execute this command:

	# asterisk -r

Once the Asterisk client is connected to the Asterisk server, you can use Asterisk's command-line interface to issue queries and commands about the telephony server. These include listing calls in progress, listing used and unused channels, and stopping the Asterisk server.

Starting the server

You can start by using asterisk executable, service command or via init script.

Shutting down the server

You can shut down the server using one of several Asterisk CLI commands:

The "restart" commands stop and then restart the Asterisk server process, which can be helpful in situations where the server's configuration has changed significantly and needs to be restarted. The "stop" commands just shut down the Asterisk server process. You'll have to execute the Asterisk program in server mode to get it running again.

The "now" and "when convenient" arguments tell Asterisk how quickly to shut down or restart. If you want to interrupt the current calls and tasks in progress on the server, "now" is appropriate. If you want Asterisk to wait until all the calls and tasks are finished and there is no call activity at all, "when convenient" is appropriate. Generally, especially if you're planning to have any callers besides yourself on the system, get in the habit of using "when convenient."

Although the Asterisk console may not look like much, it is a wonderful tool for checking on the status of Asterisk, as well as diagnosing problems. We can type help to get a list of commands.

There are some parts of Asterisk that require a restart in order to reflect changes. To restart Asterisk, we first must choose when we will be restarting. We have three main choices:

  1. now: This option stops all calls in progress, immediately stops Asterisk and starts it again.

  2. gracefully: This option does not stop calls in progress, but does not allow any new calls to be started. When all calls that are in progress are completed, the server will restart. Be careful, as a hung channel will basically disable your server.

  3. when convenient: This is my favorite option. This option does not end any calls in progress, and allows new calls to start as usual. When there are no calls in progress, the server will restart. This means that incoming and outgoing calls are not interrupted except for the short period of time in which Asterisk is actually restarting. This would not work, of course, on high-load servers, as there may never be a time when there are no calls in progress, and it will also not work if a channel is "stuck", meaning the server thinks it has a call in progress, but it does not.

We restart Asterisk thus:

CLI> restart <choice>

For instance, if we wanted to restart now, we would type:

CLI> restart now

Now is a good time to play around with the console interface. Get comfortable with it. Experiment with the Tab key to auto-complete commands, and try different verbosity levels to see what information is displayed for each.

I cannot stress enough that now is the time to play with the server. If it is going to be broken by a mistake, it is better that the mistake be made before calls are going through it. If Asterisk stops working, we can go back to the beginning of this chapter and reinstall with minimal time.

Recommended Links


Last modified: January 27, 2013