Skip to content

Installing on FreePBX

Gustavo Giráldez edited this page Jun 12, 2015 · 5 revisions

Follow these steps to get Verboice running on top of a FreePBX box. These instructions assume that you already have a FreePBX system installed and running, and you are able to login as root to run these shell commands.

Notes about FreePBX and conflicts with Verboice

The Fail2ban module on FreePBX can interfere with communications to a GSM gateway/SIP server if you are accessing it on its own ipaddress on the network.

Do not install IPv6 networking as this causes conflicts with Verboice.

Prerequisites

There are some libraries and packages needed to run Verboice.

Erlang

We will use the prebuilt binaries from Erlang Solutions. First add the repository:

# wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
# rpm -Uvh erlang-solutions-1.0-1.noarch.rpm

Then install the Erlang packages using yum:

# yum install -y erlang

Tools and libraries

Enable the Extra Packages for Enterprise Linux (EPEL) repository first:

# yum install -y epel-release

Then install the required tools and libraries:

# yum install -y gcc git make openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel libxml2-devel libxslt-devel zeromq3-devel mysql-devel nodejs festival monit

We will compile and install some libraries from source, so we need to add /usr/local/lib to the library path. To do that, create a file /etc/ld.so.conf.d/local.conf with the path and run ldconfig to update the cache:

# echo /usr/local/lib > /etc/ld.so.conf.d/local.conf
# ldconfig

Next compile and install lame:

# wget http://sourceforge.net/projects/lame/files/lame/3.98.4/lame-3.98.4.tar.gz
# tar xvfz lame-3.98.4.tar.gz
# cd lame-3.98.4
# ./configure && make && make install

Ruby

Currently there's not official Ruby package for the version required by Verboice (as of this writing 1.9.3-p550, but check https://github.com/instedd/verboice/blob/stable/.ruby-version), so we will use ruby-build to compile from source and install to /usr/local.

Checkout and install ruby-build:

# git clone https://github.com/sstephenson/ruby-build.git
# ruby-build/install.sh

And then build and install Ruby and required gems:

# ruby-build 1.9.3-p550 /usr/local
# gem install bundler
# gem install passenger

Prepare MySQL database

Login to the MySQL console with the root user and the password set during FreePBX setup:

# mysql -u root -p

Now run the following commands to create the database for Verboice:

mysql> create database verboice;
mysql> grant all on verboice.* to 'verboice'@'localhost' identified by 'secret';
mysql> flush privileges;
mysql> exit

Prepare Verboice

Checkout the source code

Let's checkout the stable branch of Verboice code:

# cd /opt
# git clone -b stable
# cd verboice

Configure Verboice

Run the following commands to modify config/database.yml using the credentials in the MySQL preparation section above:

# script/update_yml_config config/database.yml production username verboice
# script/update_yml_config config/database.yml production password secret

Update config/verboice.yml with your hostname:

# script/update_yml_config config/verboice.yml default_url_options host my-freepbx-host.mydomain:3000
# script/update_yml_config config/verboice.yml asset_host http://my-freepbx-host.mydomain:3000/

Lastly, update the broker config file at broker/verboice.config:

# script/update_erl_config broker/verboice.config verboice db_name verboice
# script/update_erl_config broker/verboice.config verboice db_user verboice
# script/update_erl_config broker/verboice.config verboice db_pass secret
# script/update_erl_config broker/verboice.config verboice asterisk_config_dir /etc/asterisk
# script/update_erl_config broker/verboice.config verboice asterisk_sounds_dir /var/lib/asterisk/sounds
# script/update_erl_config broker/verboice.config verboice crypt_secret super_secret

The last value (crypt_secret) must be the same as the encryption_key for the production section in config/credentials.yml.

Lastly, open the file broker/verboice.config and find the line/section that contains:

{poirot,[{source,<<"verboice-broker">>},{receiver,[]}]},

and change it to:

{poirot,[{source,<<"verboice-broker">>},{sender,zmq}]},

Please note the trailing comma.

Prepare Verboice to run

Next, install the bundler gems and download the broker dependencies:

# bundle install --deployment --path vendor/bundle --without development test
# (cd broker && make)

And compile the web assets and load the database schema:

# rake assets:precompile
# rake db:schema:load RAILS_ENV=production

Testing

Test the web application

You can now test that the web application works by manually starting Passenger:

# passenger start -e production

Try navigating to http://localhost:3000. You should get the welcome page. Type Ctrl-C in the console to stop Passenger.

Test the broker

Start the broker manually:

# cd broker
# make run

If everything is setup correctly, you should be in the Erlang console. Run the command:

1> application:which_applications().

(note the final period) to check that the application is running successfully (locate a line that reads {verboice, [], "1"}). Exit by pressing Ctrl-G, then g and Enter.

Setting up automatic startup

Setup monit for starting and monitoring all the components. First, enable Monit by running:

# chkconfig --add monit
# chkconfig monit on

Create a Monit control file in /etc/monit.d/verboice with the following contents:

check process verboice-web
  with pidfile /var/run/verboice-web.pid
  start "/usr/local/bin/passenger start /opt/verboice -e production -d --pid-file /var/run/verboice-web.pid"
  stop "/usr/local/bin/passenger stop --pid-file /var/run/verboice-web.pid"
  group verboice

check process verboice-broker
  with pidfile /var/run/verboice-broker.pid
  start "/bin/bash -c '/usr/bin/env HOME=/opt/verboice PATH=/usr/local/bin:$PATH make -C /opt/verboice/broker run-prod >> /opt/verboice/log/broker.log 2>&1 & echo $! > /var/run/verboice-broker.pid'"
  stop "/bin/bash -c 'kill -TERM `cat /var/run/verboice-broker.pid`'"
 
check process verboice-delayed-job
  with pidfile /var/run/verboice-delayed-job.pid
  start "/bin/bash -c 'cd /opt/verboice; /usr/bin/env HOME=/opt/verboice PATH=/usr/local/bin:$PATH RAILS_ENV=production /usr/local/bin/rake jobs:work >> /opt/verboice/log/delayed.log 2>&1 & echo $! > /var/run/verboice-delayed-job.pid'" timeout 60 seconds
  stop "/bin/bash -c 'kill -TERM `cat /var/run/verboice-delayed-job.pid`'"

Now restart Monit to start Verboice services:

# service monit restart
# monit -g verboice start all

Configure Asterisk

Some configuration files has to be changed by hand to connect Asterisk with Verboice. Let's add a custom context for Verboice. Edit the file /etc/asterisk/extensions_custom.conf and add:

[verboice]
exten => _X!,1,Answer
exten => _X!,n,Wait(1)
exten => _X!,n,AGI(agi://127.0.0.1:19000,,${EXTEN})

[verboice-restart]
exten => _.,1,AGI(agi://127.0.0.1:19000,${EXTEN})

Also, add an AMI account for Verboice editing the file at /etc/asterisk/manager_custom.conf:

[verboice]
secret=verboice
read=all
write=all

And finally, change /etc/asterisk/sip_custom.conf to load the additional configuration files maintained by Verboice:

#include sip_verboice_channels.conf
#include sip_verboice_registrations.conf

Then restart Asterisk with:

# service asterisk restart

Configure FreePBX

Now we are ready to set FreePBX to comunicate with Verboice.

Create Custom Destination

For each Verboice channel we must create a custom destination. For this go to "Tools > Custom Destinations" and add a new destination with the address: "verboice,<channel number>,1", where is the ID of the channel create in the Verboice interface.

Route calls from outside

For calls coming from outside the Asterisk box (FXO or E1 cards for example) go to "Setup > Inbound Routes" and create a route using the Custom Destination created before as the destination of this route.

Route calls from inside

For calls generated from inside the Asterisk box (calls made from soft phones) go to "Setup > Misc Applications" and create a new application with any desired feature code number and using the Custom Destination created before as the destination of this application.