Hack41.Turn Your Linux Box into a PBX


Hack 41. Turn Your Linux Box into a PBX

Install and test the Asterisk open source telephony server on your Linux PC.

Some RPM packages are available to simplify Asterisk's installation, but manual compilation is relatively easy. So I'm going to show you how to download, compile, and install Asterisk the "old-fashioned" way. The development branch you'll download from is stable, though once you get comfortable with Asterisk, you'll want to jump out on the bleeding edge and try the developer releases, too. Each release tends to introduce something new and worthwhile, even if it's not in the stable branch yet.

The easiest place to download the Asterisk software is the CVS repository at Digium, the company responsible for Asterisk and some of the hardware components that work with it. To access the CVS repository, you'll need to be logged into your Linux computer at a shell prompt as root. Type these commands to run the CVS check-out routine and download the source code:

 $ cd /usr/src $ export CVSROOT=:pserver:anoncvs@cvs.digium.com:/usr/cvsroot $ cvs login $ cvs checkout zaptel libpri asterisk 

Alternatively, you can specify a particular version of Asterisk:

 $ cvs checkout -r v1-2 zaptel libpri asterisk 

When prompted, use anoncvs as a password. If you don't use /usr/src as the local location for compiling programs, substitute the appropriate path. The CVS client you're running here will create the /usr/src/asterisk directory that contains all the Asterisk source code. Once the download completes, you are ready to begin compiling.

Asterisk consists of several software components for Linux. Not all of these packages are required, as some of them are drivers for Digium's interface cards. If you aren't planning to use Digium's cards, you'll need to build only the last of the three, asterisk:


libpri

A driver module that supports Zaptel-compliant interface cards (described in this chapter's introduction) so that ISDN and PRI trunks can be interfaced with Asterisk


zaptel

A driver module that allows legacy telephone line interfaces cards that provide FXO, FXS, and T1/E1 signaling to be used with Asterisk


asterisk

A modular software daemon that provides telephony, management, and call-accounting features, including voicemail, Session Initiation Protocol (SIP) telephone support, dial plan, and so on; in a nutshell, Asterisk is an all-software PBX

If you're wondering about these technical terms, don't worry. As you experiment with Asterisk and learn more about VoIP, they'll become very familiar. For now, just compile and install all three packages.

After you run the CVS download, the source code for each Asterisk software component is sitting in its respective directory in /usr/src. Let's compile each software component by issuing the following commands. Again, you need to compile zaptel and libpri only if you're planning on using legacy or Digium interface cards. Many of the examples in this book use legacy devices, so it's probably a good idea to compile them all right now. Here is the sequence of commands:

 # cd zaptel # make clean ; make install # cd ../libpri # make clean ; make install # cd ../asterisk # make clean ; make install 

Do compile Zaptel before you compile Asterisk, or else Zaptel features will be missing from the Asterisk build. What is Zaptel, you ask? Keep reading….


It should take 20 minutes at most to complete the whole build on an average PC. Once built, Asterisk is ready to use. But you can't race a Ferrari without a training lap on the test track, and you can't really use Asterisk until you understand the basics of configuring it. So it's time for driving school. To get started, run this command in the Asterisk source directory:

 # make samples 

This creates a basic sample set of Asterisk configuration files and places them in /etc/asterisk. You might want to peruse these filesespecially extensions.conf and sip.conf, where you'll likely be spending a lot of time.

If you've used an RPM package or some other precompiled Asterisk distribution (or if you've obtained a Linux distribution with Asterisk already installed), you can still obtain the source distribution files from Digium's CVS repository and issue only the make samples command. This will give you the sample configuration files without actually rebuilding Asterisk on your PC.

4.2.1. Start and Stop the Asterisk Server

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.

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.

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

  • Restart now

  • Restart when convenient

  • Stop now

  • Stop when convenient

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."

All of these commands ultimately shut down Asterisk. If you make a configuration change that doesn't require a complete restart, like a change to a certain phone extension, you can just use reload at the Asterisk prompt.


4.2.2. Linux-Specific Start and Stop Scripts

Depending on your particular flavor of Linux, be it Fedora, Debian, SuSE, or something else, you'll find your system's normal startup scripts in a place that's unique to each flavor. Fortunately, Asterisk's Makefile has an option that lets you automatically generate start and stop scripts that are specific to your flavor of Linux. In your Asterisk src directory, just issue the command make config, and the scripts will be installed. These scripts start and stop not only Asterisk, but also the Zaptel drivers, if you've compiled them.

As it stands at this point, your Asterisk server won't be especially useful. You'll be able to explore the Asterisk command prompt with asteriskr, but the truly fun stuff, like hooking up phone lines and phones, is still to come. To try out Asterisk's cool demonstration routineslike interactive voice response (IVR) and an Internet-based VoIP callyou've got to configure a phone of one sort or another to access the Asterisk server. Keep reading!




VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

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