Asterisk can be started several ways from the command line. By default Asterisk will run as a daemon if not passed any parameters. You can do this by running /usr/sbin/asterisk. We assume that /usr/sbin/ is the directory where the Asterisk binary has been installed.
We can also pass parameters to Asterisk to allow us to do various things such as connect to the console, control the verbosity of the console, run Asterisk in debugging mode and dump cores upon crashing. These can be very useful tools to help manage your system.
Parameters that can be passed to the Asterisk binary include:
|c - console. Starts Asterisk in the foreground (implies -f), with a command line interface (CLI) which you can use to monitor the state of the system and issue commands|
|v - level of verbosity. Multiple v's give more verbosity|
|d - enter debugging mode|
|g - dump core upon crashing|
|h - help|
|C <configufile> - Start with a configuration file other than the default /etc/asterisk/asterisk.conf|
|f - Foreground. Starts Asterisk but does not fork as a background daemon|
|r - Remote console. Starts a CLI console which connects to an instance of of Asterisk already running as a background daemon|
|n - Disable console colorization (for use with -c or -r)|
|i - Prompt for cryptographic initialization passcodes at startup|
|q - Quiet mode for output supression|
|x <cmd> - execute command <cmd> (only valid with -r)|
If we wish to run Asterisk in console mode we simply append the -c command line paramater after the binary name. If you need to perform multiple commands at the same time you can concatenate multiple parameters together.
For example, lets say we want to start Asterisk in console mode with several levels of verbosity and debugging. That can be done by running /usr/sbin/asterisk -cvvvd.
What if we've started Asterisk as a daemon and we wish to reconnect to the console? To reconnect to the Asterisk console run /usr/sbin/asterisk -r.
The safe_asterisk script is the preferred way to run Asterisk. This script starts Asterisk and monitors it to make sure it is still running. If the Asterisk process dies, the script will attempt to restart it.
You can find a copy of the script in /usr/src/asterisk/contrib/scripts/safe_asterisk. The script is copied to /usr/sbin/ during the installation process as well. Inside the script there are several options we can set.
TTY=9 # TTY (if you want one) for Asterisk to run on CONSOLE=yes # Whether or not you want a console #NOTIFYfirstname.lastname@example.org # Who to notify about crashes ASTARGS=""
The TTY variable allows you to set which TTY console you would like the Asterisk CLI to run on. If you leave this variable blank then Asterisk will be started as a daemon. When CONSOLE=yes then Asterisk is started in console mode. NOTIFY is used to send an email to the address specified if Asterisk every crashes. The email is sent using the 'mail' program. ASTARGS is used to start Asterisk with any optional arguments which you specify. The Asterisk script will start Asterisk with the -vvvg arguments plus those specified in ASTARGS.