Tuesday, October 09, 2007

Asterisk "too may open files"

Another quick Asterisk pointer.

If you are running a large amount of traffic on your Asterisk box you are likely to come across this message.

"unable to create from pipe: too many open files"

What this means is that Asterisk has exceeded the per-process limit on open files.

You can get the per-process limit for you system by opening a shell and typing 'ulimit -n'. My system, Ubuntu 7.04 is set at 1024.

I find that the easiest way to set this is by opening the /usr/sbin/safe_asterisk script and finding the existing line 'ulimit -c unlimited', and adding a line below that of 'ulimit -n 65536'.

The safe_asterisk script is a script commonly used to launch Asterisk because it will also monitor and restart Asterisk if it crashes. So when you use it to launch Asterisk, the line we added will be executed and will increase the limit for Asterisk.

Please note that you should only need to do this on Asterisk 1.2 systems. On Asterisk 1.4, the safe_asterisk script has been modified to do this out of the box.

Dan


Friday, August 24, 2007

Python File Backup Script

I wrote this backup script in Python to do backups on some of the servers I maintain.

Features
- simple & quick to configure & install
- full & incremental backups
- configurable backup directories
- configurable full backup dates
- backups in tar format, no special software for restores
- email notification of problems
- backup files to any valid path (nfs, smb, usb drive, etc...)

Requirements
- python
- system supporting the tar command (linux, unix, cygwin, etc...)

For installation instructions or more information about the scripts check out the included README file. Scripts are released under the LGPL.

You can download them from here.

Dan

** UPDATE **

I've updated the link to a newer version (1.0.1). The original version was written to write backups to an external drive, so it assumed that the drive needed to be mounted first. If the drive was already mounted it would remount it. So I've added an option where you can now specify if the script should mount the drive first.

Sunday, July 22, 2007

Asterisk Ubuntu Feisty Fix

Starting Asterisk PBX: /usr/sbin/safe_asterisk: 108: Syntax error: Bad fd number

I ran into this issue while running Asterisk 1.2.22 on Ubuntu Feisty 7.04. It appears that the 'safe_asterisk' start-up script has an issue with it. In Ubuntu Feisty, the default shell (/bin/sh) is no longer bash, it is dash. The 'safe_asterisk' script needs to reference bash. So changing the first line from '#!/bin/sh' to '#!/bin/bash' fixes the issue.

Hope this helps someone.

Friday, March 09, 2007

FizzBuzz Problem

This has been on digg recently and there was some talk about it recently at work.

If you are interviewing someone and need a programming question to ask, this is a good one. Any competent programmer should be able to give you a solution.
This puzzle is typically given to all levels of programming candidates (newbie to senior) during their interview. According to numerous people, only about 10% of the programmers can pass it (even the seniors). Can you? (hint… its actually not that hard if you figure out the key).

Problem:

Write a (substitute language here) program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
The problem is actually simple and has a simple strait forward solution, which is what makes it such a good question to ask.

A simple solution would be to setup a loop from 1 through 100, checking for numbers that are divisible by 3, 5, or both and printing the correct output.

Since taking the simple solution is boring, here's a python solution that I came up with that is only one line long.

print "\n".join([((num % 3 == 0) and (num % 5 == 0)) and 'FizzBuzz' or (num % 3 == 0) and 'Fizz' or (num % 5 == 0) and 'Buzz' or str(num) for num in range(1, 101)])

Anyway, if you think you have a cool solution post it here.

Dan