Yum looking for a media repo

Ever had a problem where yum will look for the media repository, despite the fact that there is no configuration in place to use that repo, and you’ve completely cleaned out the cache?

This had me completely stumped, however I finally found the fix.

If you create a local yum mirror repository using the ISO images (I did this so I didn’t have to download all the RPMs again), the repodata/ directory ends up contains some XML files that specifically identify it as a local media repo, not as an online one. These XML files then screw up yum and make it look like yum is trying to connect to a non-existent media repository.

The fix is to that if you are creating a yum repo, make sure the repodata/ folder is mirrored from an existing online repo, not an ISO.

Misc tips and tricks

DD PROGRESS REPORTS
Redhat magazine has an interesting tip by Andrew C. Dingman on how you can make the dd command give you progress reports whilst it is still running. Read the article here

History of Slashdot
Slashdot is a very popular news site for computer geeks. If you are one of it’s thousands of readers, you may be interested in the recent “History of Slashdot” articles CmdrTaco wrote.

Part 1: Chips & Dips
Part 2: Explosions
Part 3: Going Corporate
Part 4: Yesterday, Today, Tomorrow

Computer Paranoia
I came across a collection of humorous tales of computer-illiterate users. Read here

Adjust dates by months and years in perl

I recently needed to subtract 1 month from a date for a perl program I was working on. Whilst subtracting days or weeks is easy as you can just convert it to a timestamp, adjusting months or years is far harder due to all the complexity of having to deal with different numbers of days in months, leap years, etc.

Took me a little while to find the best function to use, but there is a perl module that can do this for you called Date::Calc, which provides a function called Add_Delta_YM.

This function will handle all the complexity, and will round to the closet date in the previous month, handling situations like “2007-03-31 – 1 month == 2007-02-28” in a nice fashion.

Below is a code sample:

 #!/usr/bin/perl

 use strict;
 use Date::Calc qw(:all);

 my $year  = "2007";
 my $month = "3";
 my $day   = "31";

 my $Dy    = "0";    # number of years to adjust by
 my $Dm    = "-1";   # number of months to adjust by (-1 means go back 1 month)

 ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $Dy,$Dm);

 print "$year-$month-$day\n";

If you need to do any other type of date manipulation, I suggest you look into the Date::Calc module to see if it fulfills your needs. As an added plus, if your a RHEL/CentOS user the module is available in the base repository.

OpenVPN AutoRestart Script

I often use OpenVPN for my VPN needs. It’s an Open Source SSL VPN with a whole bunch of features and plenty of configuration flexibility.
However, one issue is that when I make a configuration change and reload openvpn, all the clients have to reconnect. Usually this happens automatically, but sometimes some users lose their sessions and (understandably) get annoyed.

This then requires the configuration of a cronjob so OpenVPN gets restarted at a time that doesn’t annoy users, but sometimes it gets forgotten or another admin makes a change and doesn’t restart the service.

I’ve written a small script that uses md5sum to check if the openvpn config files have changed, and then restart the OpenVPN service automatically. I have it in /etc/cron.daily/ so it gets called at 4:00am.

Download the OpenVPN auto-restart script

This script could be easily adapted to handle any service you want.

Sendmail Permissions Problem

I came across a very interesting sendmail issue the other day. I found that I was able to send emails, both as root and also as apache. However, whenever I ran a particular email script as root which simply opened up sendmail and passed it commands to generate an email, I would get the following error:

Aug 31 11:19:10 myserver sendmail[30588]: l7UNJAOD030588: SYSERR (apache):
collect: Cannot write ./dfl7UNJAOD030588 (bfcommit, uid=48, gid=51): Permission denied
Aug 31 11:19:10 myserver sendmail[30588]: l7UNJAOD030588: from=apache,
size=903,, nrcpts=1, relay=apache@localhost
Aug 31 11:19:10 myserver sendmail[30588]: l7UNJAOD030588:   0:
fl=0x0, mode=10600: FIFO: dev=0/6, ino=2075297, nlink=1, u/gid=48/48, size=0
Aug 31 11:19:10 myserver sendmail[30588]: l7UNJAOD030588:   1:
fl=0x1, mode=10600: FIFO: dev=0/6, ino=2075290, nlink=1, u/gid=48/48, size=0
Aug 31 11:19:10 myserver sendmail[30588]: l7UNJAOD030588:   2:
fl=0x1, mode=10600: FIFO: dev=0/6, ino=2075291, nlink=1, u/gid=48/48, size=0
Aug 31 11:19:10 myserver sendmail[30588]: l7UNJAOD030588:   3:
fl=0x2, mode=140777: SOCK localhost->[[UNIX: /dev/log]]
Aug 31 11:19:10 myserver sendmail[30588]: l7UNJAOD030588:   4:
fl=0x1, mode=20666: CHR: dev=0/16, ino=1271, nlink=1, u/gid=0/0, size=0
Aug 31 11:19:10 myserver sendmail[30588]: l7UNJAOD030588: SYSERR (apache):
queueup: cannot create queue file ./qfl7UNJAOD030588, euid=48, fd=-1, fp=0x0: Permission denied

This problem really had me puzzled because:
1) I could email without a problem as both apache and root with other scripts and manual commands.
2) I was running the script as the root user – apache wasn’t involved, and I could find no reference to apache in the script itself.
3) Permissions on /var/spool/mqueue were correct.

I eventually discovered that the problem was being caused by incorrect permissions on /var/spool/clientmqueue. After changing it from 740 to 770, the problem was resolved, and the permissions now look like this:

drwxrwx---  2 smmsp  smmsp  4096 Sep  9 01:10 clientmqueue

I still don’t know where the apache reference in the errors came from, but at least I found the fix. :-)

Sendmail Technical Lesson

Before this problem occured, I did not know what the purpose of the clientmqueue directory was, so here’s a few notes about what it’s actually doing.

Sendmail stores all the mail in it’s queue in 2 files per email, with names of qf* (header) and df* (content).

By default, there are 2 parts to sendmail. The first is a non-root daemon, which sometime queues emails in /var/spool/meueue, and receives emails from programs on the local system. The second part is the main damon which comes and reads in the emails found at the clientmqueue location, and sends them off, sometimes using /var/spool/mqueue to store unprocessed mail.

Sendmail works this way because it means that sendmail doesn’t need to run as suid root, which is bad from a security perspective.

Automatic Shutdown Script

At home I have a powerful Linux computer with plenty of disk space which I use for storing lots of large files such as ISO images and for assisting with source package builds.

However, it is also a rather noisy, power-consuming computer, and because I don’t need it all the time (maybe once every 2 days) I decided to write a script which will monitor it, and shut it down if it’s
not being used.

So my result: a perl script which monitors for logged in users with “who” and for any active samba shares with “smbstatus”.

Download Jethro’s Automatic Shutdown Script

Read the start of the file for installation/configuration information, but it’s pretty simple. It also isn’t too complex, so if you know basic perl you can add support for other checks that may suit you (eg: NFS, CPU usage, etc).

Hope someone else finds this useful… :-)

rdiff-backup future date errors

I recently came across an interesting error when using the rdiff-backup program:

Cannot change mtime of /backupdestdir/somedir/rdiff-backup.tmp.23 to 3937075508
problem is probably64-32bit conversion

Turns out the cause of this error is if the date of the file in question has been modified in the future – in my particular case 2094. :-)

You can change the modification date to the current date by running the command “touch filename”.

Stop the console bell

Just the other day, a colleague of mine came across the method to stop the console bell. For those of you unfamiliar, the console bell is very annoying because when you use tab completion on a virtual terminal, it will emit beeps. This rapidly becomes VERY frustrating.

So – the fix is to run:

setterm -blength 0

Simple eh? :-)

Note: This will work for the virtual terminals (eg: /dev/tty3), but not necessarily for programs like xterm or gnome-terminal.

Asterisk with Telstraclear NZ E1

For the last week, I’ve been diagnosing a problem with our VoIP system at work. Our setup is quite simple, and consists of an Asterisk server with a Digium E100P card connected to a TelstraClear E1 connection.

Everything seemed to be working fine, however we discovered that calls from Telecom NZ landlines work fine when directly dialing to phones (DDI), but would be disconnected after ~25seconds when calling to the IVR (Digital menu – eg: “press 1 for blah, 2 for foo”).

No other phone providers had a problem – TelstraClear landlines, Vodafone and Telecom mobiles all worked. :-/

As you can imagine, this problem caused a lot of headaches, but we finally managed to track it down – Asterisk wasn’t sending a Q931 ALERTING message on the IVR calls, but did for the DDI calls.

After filing a bug report with digium, we were pointed to the Ringing() command which when I added before the Answer command in the IVR extension config, caused Asterisk to send a couple of rings, and an ALERTING signal.
Once we tested with the ALERTING signal, everything worked fine! This may be a problem with some of the equipment Telecom NZ uses, or just some strange incompatibility between 2 devices somewhere on the voice network. It certainly doesn’t seem very common, due to the complete lack of information on the web about anyone having a problem like this.

Since we use FreePBX for Asterisk, I had to patch it so it would add the ringing command to the configuration when it generates it. I’m going to be upgrading FreePBX next week, but once I do, I’ll upload the patch here for anyone needing it. :-)

UPDATE – 28 May 2007

I just upgraded our pabx from Trixbox 1.2.0 to 2.2, and found that the problem no longer occurs. After checking though the config, I found there has been an addition of a Ringing() command in /etc/asterisk/extensions.conf.

Find the [from-zaptel] section and adjust it to look like this:

[from-zaptel]
exten => _X.,1,Set(DID=${EXTEN})
exten => _X.,n,Goto(s,1)
exten => s,1,NoOp(Entering from-zaptel with DID == ${DID})
; Some trunks _require_ a RINGING be sent before an Answer.
exten => s,n,Ringing()