When I took on the task of setting up an office PBX I decided early on that I wanted to use version control software to help with the maintenance and it’s proved it’s self several times.

I’ve setup a simple layout for the repository which looks this:

PBX
    Release
       Running
           1.0
           1.1
       Static
           1.0
           1.1

every now and then or when I’ve done a lot of work I copy the current running/version-number to the next number up and also over to static/New-versionNumber. The static side is never changed after it’s copied. This means that with one simple command I can revert back to an older configuration if I really screw up.

Under each VERSION is the folder structure for all the asterisk configs:

config
 Firmware
 scripts
 sounds
 misc
 SRC
 tftpboot
 www

config is really /etc/asterisk, all others are as they seem.. Now on the PBX it’s self I create a dir at the top level: mkdir /PBX, and check out my latest running version to this dir. I can then link all the directories around back to this dir, thus one check out.

 ln -sf /PBX/config /etc/asterisk
 rm -rf /var/lib/asterisk/agi-bin 
 ln -sf /PBX/config/AGI /var/lib/asterisk/agi-bin
 rm -rf /tftpboot
 ln -sf /PBX/tftpboot /tftpboot
 rm -rf /var/www
 ln -sf /PBX/www /var/www
 ln -sf /PBX/misc/DHCPD/dhcpd.conf /etc/dhcpd.conf
 ln -sf /PBX/misc/ZAPTEL/zaptel.conf /etc/zaptel.conf
 ln -sf /PBX/sounds /var/lib/asterisk/sounds/PBX

I can now edit my configuration using my favorite text editor (TextMate http://www.macromates.com) on my Mac, commit changes I’ve made, then check them out on the PBX. This also allows me to run tests on my test PBX simply by checking out the changes on it. When I’m happy I can check out the update back to the production PBX. No more guessing which files have changed!!

Using this method, if my PBX dies, no big deal. Just rebuild the base OS and then checkout the configuration again.