Section 3.11. Loading Asterisk

3.11. Loading Asterisk

Asterisk can be loaded in a variety of ways. The easiest way is to start Asterisk by running the binary file directly from the Linux command-line interface. If you are running a system that uses the init.d scripts, you can easily start and restart Asterisk that way as well. However, the preferred way of starting Asterisk is via the safe_asterisk script.

3.11.1. CLI Commands

The Asterisk binary is, by default, located at /usr/sbin/asterisk . If you run /usr/sbin/asterisk , it will be loaded as a daemon. There are also a few switches you should be aware of that allow you to (re)connect to the Asterisk CLI, set the verbosity of CLI output, and allow core dumps if Asterisk crashes (for debugging with gdb ). To explore the full range of options, run Asterisk with the - h switch:

 #  /usr/sbin/asterisk -h  

Here is a list of the most commonly used options:



-c

Console. This allows you to connect to the Asterisk CLI.



-v

Verbosity. This is used to set the amount of output for CLI debugging.



-g

Core dump. If Asterisk were to crash unexpectedly, this would cause a core file to be created for later tracing with gdb .



-r

Remote. This is used to reconnect remotely to an already running Asterisk process. (The process is remote from the standpoint of the console connecting to it but is actually a local process on the machine. This has nothing to do with connecting to a remote process over a network using a protocol such as IP, as this is not supported.)



-rx "restart now"

Execute. Using this command in combination with - r allows you to execute a CLI command without having to connect to the CLI and type it manually.

Let's look at some examples. To start Asterisk and connect to the CLI with a verbosity level of 3, use the following command:

 #  /usr/sbin/asterisk -cvvv  

If the Asterisk process is already running (for example, if you started Asterisk with /usr/sbin/asterisk ), instead use the reconnect switch, like so:

 #  /usr/sbin/asterisk -vvvr  

If you want Asterisk to dump a core file after a crash, you can use the - g switch when starting Asterisk:

 #  /usr/sbin/asterisk -g  

To execute a command without connecting to the CLI and typing it (perhaps for use within a script), you can use the - x switch in combination with the - r switch:

 #  /usr/sbin/asterisk -rx "restart now"  

If you are experiencing crashes and would like to output to a debug file, use the following command:

 #  /usr/sbin/asterisk -vvvvvvvvvc  tee /tmp/debug.log  

3.11.2. Red Hat-Style Initialization Script

If you ran the make config command earlier (or manually copied the initialization scripts ), you can start and restart Asterisk with the following commands:

 #  /etc/rc.d/init.d/asterisk start  #  /etc/rc.d/init.d/asterisk stop  

3.11.3. The safe_asterisk Script

The main purpose of the safe_asterisk script is to dump a core file if Asterisk fails and to automatically restart it. There is also a notify option within the script, which, if set, will send an email letting you know that Asterisk died unexpectedly. An added benefit of the script is that it will load the Asterisk CLI on terminal interface 9 (by default; this is configurable), so you can easily switch to that window to monitor your Asterisk system.

The default location of the safe_asterisk script is /usr/sbin/safe_asterisk , and it can be executed as such. Let's review the various options contained in the safe_asterisk script:

 CLIARGS="$*"              # Grab any args passed to safe_asterisk     TTY=9                     # TTY (if you want one) for Asterisk to run on     CONSOLE=yes               # Whether or not you want a console     #NOTIFY=ben@alkaloid.net  # Email address for crash notifications 

The first line simply allows you to pass arguments to the safe_asterisk script from the Linux CLI; it should not be edited directly. TTY=9 specifies the Linux console on which to run the Asterisk CLI output. You can disable this feature by specifying CONSOLE=no . If you would like to be notified if Asterisk dies suddenly and requires a restart, uncomment the NOTIFY line and replace ben@alkaloid.net with your email address. Note that the crash notifications are sent with the mail command, so your system must be set up to process and send email.



Asterisk. The Future of Telephony
Asterisk: The Future of Telephony: The Future of Telephony
ISBN: B0026OR3OO
EAN: N/A
Year: 2001
Pages: 380

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net