asterisk asterisk-addons astierks-mysql freepbx mysql Ubuntu

Final Asterisk clean up

This time I’m going to go through the final pieces of the Asterisk clean up on my Ubuntu 10.04 setup.

There were two annyoing things left behind by my install and setup of Asterisk.

  1. When I shutdown freepbx (aka amportal) the Asterisk instance would crash and then restart
  2. Ubuntu would want to update asterisk-mysql package

I’m going to show you how I got around these two issues. Firstly the amportal startup string and how to kill that nasty Asterisk crash and core dump.

The script I use to startup freepbx is below

# Provides: asterisk
# Required-Start: \$network \$syslog
# Required-Stop: \$network \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Asterisk daemon.
# Description: This script handles start/stop states of asterisk.

set -e
set -a

#test -x $DAEMON || exit 0

d_start() {
amportal start
d_stop() {
amportal stop
d_reload() {
amportal restart
case "$1" in
echo -n "Starting $DESC: $NAME"
echo "."
echo -n "Stopping $DESC: $NAME"
echo "."
echo -n "Restarting $DESC: $NAME"
sleep 10
echo "."
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
exit 0

Save this to /etc/init.d/amportal and then do the following

update_rc.d amportal defaults 80 20
update_rc.d -f asterisk remove

so that FreePBX will come up when you boot and remove the Asterisk from starting on its own. You could also use the sysv-rc-conf tool which allows you to do this visually.
You notice that this runs the amportal script which is located at /usr/local/sbin. Inside of there andother script is invoke called freepbx_engine. This is typically located at /var/lib/asterisk/bin. Inside there you will see lines like

killall -9 safe_asterisk
/usr/sbin/safe_asterisk -U asterisk ...
/usr/sbin/asterisk -rx "core stop gracefully" | grep -v "No such command"
/usr/sbin/asterisk -rx "stop gracefully" | grep -v -E "No such command|deprecated"

What is Safe_Asterisk? This is a script which starts a loop and runs Asterisk inside the loop. If Asterisk was to die for some reason then it detects this and restarts Asterisk.

There are two problems which I had with this. Firstly safe_asterisk starts Asterisk in the foreground, so my startup script would appear to hang after Asterisk started. Second when I killed the script (by using Ctrl+C), Asterisk would stop and crash and then restart and sometimes it would fail to restart and keep re-trying.

Getting Asterisk to start in the background was simple enough, but the crashes and attempted restarts still happened when I shutdown freepbx.

The solution I found was to do utilize the existing Asterisk startup script. I replaced the above lines with this

#killall -9 safe_asterisk
killall -9 asterisk
#/usr/sbin/safe_asterisk -U asterisk -G $AMPASTERISKGROUP
/etc/init.d/asterisk start
#/usr/sbin/asterisk -rx "core stop gracefully" | grep -v "No such command"
#/usr/sbin/asterisk -rx "stop gracefully" | grep -v -E "No such command|deprecated"
/etc/init.d/asterisk stop

That solved all my problems with the starting and stopping of freepbx.

Now, if you’ve added on the Asterisk Addon from my previous post. You may find that next time you do a apt-get or aptitude to update your OS that it wants to pull down an “updated” asterisk-mysql. Do not do this! It will overwrite the addons and they will then not load. To keep from being prompted you need to pin this package at the version that its on and you will not be prompted anymore. This is thanks to this page.

echo asterisk-mysql hold | dpkg --set-selections

and to check that worked you do

dpkg --get-selections | grep asterisk

asterisk install
asterisk-config install
asterisk-mysql hold
asterisk-sounds-extra install
asterisk-sounds-main install

what more could a man want!

I hope that helps a lot more of you with using FreePBX which just gets better and better.

add ons asterisk cdr freepbx Linux mysql

Getting those Asterisk Addons into Ubuntu

I have this VOIP server in my office which is running FreePBX and Asterisk. Well its not in my office, its in a server room down the hall. Its a small AMD Duron of about 1Ghz, which is enough.

FreePBX is a great GUI and management interface for Asterisk and I encourage anyone to use it. I originally used the AsteriskGUI, but that was buggy and had severe limitations. Also, development had basically stopped on it. You know when Digium (the sponsors of Asterisk) start shipping FreePBX with Asterisk in its AsteriskNOW package – their own GUI is dead.

It took a bit of trial and error to get FreePBX installed on Ubuntu 10.04 – as there is no package for it. I also managed to get it working with lighty (lighttpd) which saved a lot of memory. And as an additional tip, disable innoDB in MySQL which will save you even more memory.

By default Asterisk logs all the calls to a CSV file. These files are very ugly and impossible to read. There is a panel in FreePBX which allows you to interrogate CDR or call records. This panel queries a MySQL database. This database is part of the FreePBX install script which managed to work for me. But to log to the database Asterisk must have the cdr_mysql addon. This does not come straight with a ubuntu package. There are a couple of steps you need to go through.

First, do not go out an grab the svn sources from digium site and compile and install. This will not work. You will most likely get these types of errors in your Asterisk full log:

Module '' was not compiled with the same compile-time options as this version of Asterisk.
Module '' will not be initialized as it may cause instability.
Module '' could not be loaded.

Follow these steps though and you will have success:

~# apt-get build-dep asterisk-mysql
~# apt-get -b source asterisk-mysql
~# dpkg -i asterisk-mysql_1.6.2.0-1_i386.deb

So what does this do? The first step downloads all the build dependencies for the add ons. The next builds the addons from the source. The last step installs the addons into the Asterisk modules folder. Thanks to the guys as Launchpad for helping everyone sort this out. See here.

Then restart your Asterisk server and you are done. I think next time I’ll show you how to get around the core dump when you shutdown Asterisk using the scripts which come with FreePBX.

Now if we could only nail down the call quality, me and the other guys at chameeya would be so happy.

knowledgeroot LAMP mysql

Spreading the knowledge

This time I’ll report on my success in installing knowledgeroot on my application server.

Knowledgeroot ( is a wiki-type open-source product written using LAMP which is meant to hold documents and pages of information. Its primary purpose is to provide documentation or information for workgroups.

LAMP for those of you who don’t know is the open-source platform for much of the websites on the internet. It is a acronym (Linux Apache MySQL PHP). See for more information on LAMP.

When you go to the knowledgeroot website – which itself uses knowledge root – the install instructions are very terse. It simply tells you to copy the files into the Apache space. Then browse to the install.php page and follow the instructions.

First I had to install Apache. This was easily done as it was already on my CentOS 5.3 server, I only had to start it when I was ready.

Rather than copy the files under Apache folders I rather was going to the alias facilty found in any modern webserver. I placed them in /usr/Knowledgeroot/knowledgeroot- and then went into the Apache config file (httpd.conf) and added in the alias knowledgebase to point to the folder above.

I then started Apache and navigated to http://localhost/knowledgebase/install.php and was confronted with the “install” page. This was just a simple page with no instructions really. Most of it I could figure out, it was only the database part which I didn’t understand. I reckoned I that I first needed to setup the database before progressing further with the install.

I pulled out my favorite took in these instances…Google. I found this page which helped immensly!
I more, or less followed those instructions, knowledgeroot is not a package on CentOS, and I had a separate user just for the knowledgeroot database. The database created was not in Innodb format so I had to copy the files over to my NAS and create a symbolic link to the folder, easy-peasy.
Then I tackled the install page and it came up with the entries to the config files and instuctions on to delete the install.php files. If the developers are reading this, the install needs to be improved! I’ve put it on my TODO list.
Then onto using it! I setup my users…a bit ugly. Again an area which needs work. And then I put some content in.

Overall its working quite well. I haven’t trained user’s on it yet. I have a load of work to finish on other things first. Plus I also had to install a IMAP server and then setup fetchmail and procmail onto my servers. Something which is still causing my trouble. More on that next time.
I certainly hope this helps others with knowledgeroot out there. There are forums of course if you get really stuck. I see this as a experiment at present. I haven’t decide whether I will build a product on top of it. There would be some licensing and technology issues that would need to be decided on first.