Mail Forwarding on OS X Server 10.5 Leopard: Using /etc/aliases

I like to have my mailserver set up so that mail sent to apache@www.example.com (through a relay at mail.example.com) comes to one of my email addresses.

On my old crufty Mac OS X Server mailserver, which runs postfix, I was wondering why mail sent to apache@www.example.com was not getting delivered, even though in /etc/aliases on mail.example.com clearly had the entries

apache: root
root: myemailaddress@mydomain.com

Instead, I was receiving errors like relay=cyrus, delay=0.13, delays=0.02/0.02/0/0.09, dsn=4.3.0, status=deferred (temporary failure. Command output: couldn't connect to lmtpd: No such file or directory_ 421 4.3.0 deliver: couldn't connect to lmtpd_

I was able to fix this by changing the relay from cyrus to local. That was OK since I am not using cyrus anyway; I have no local accounts on the mailserver.

I made the change by clicking a checkbox called "Deliver to "/var/mail" when POP & IMAP are disabled" in the OS X Server GUI.

The change has the effect of changing a line in /etc/postfix/main.cf.

Before:

mailbox_transport = cyrus

After:

mailbox_transport =

Postfix will now use the local transport, which actually checks /etc/aliases and delivers accordingly.

And yes, this is my last OS X Server and it's on the list to be migrated to RHEL.

[ Submitted by John on Tue, 2011-05-24 12:34. | | ]

Creating Open Packaging Conventions files with zip on OS X 10.6

The .docx format used by Microsoft is actually a collection of XML files (and other files) and can be opened with zip.

For example, on OS X you can use unzip at the command line to look at the OPC file like this (we'll unzip it into a directory called foo):

$ ls -l
-rw-r--r--@ 1 john  staff    13678 Feb  3 11:52 Ham.docx
$ unzip Ham.docx -d foo
Archive:  Ham.docx
  inflating: foo/[Content_Types].xml
  inflating: foo/_rels/.rels
  inflating: foo/word/_rels/document.xml.rels
  inflating: foo/word/document.xml
  inflating: foo/word/theme/theme1.xml
  inflating: foo/word/settings.xml
  inflating: foo/word/webSettings.xml
  inflating: foo/word/stylesWithEffects.xml
  inflating: foo/docProps/core.xml
  inflating: foo/word/styles.xml
  inflating: foo/word/fontTable.xml
  inflating: foo/docProps/app.xml

Now you've extracted the .docx file into a new directory called foo. You can go in there and poke around at the .xml files.

But what happens when you want to put the whole thing back together? "No problem," you might think. "I'll just use the handy-dandy Compress service to do that."

Then just rename it to foo.docx and we're all done! But...wait.

Now you're ready to take the gloves off. "I'll just do it at the command line!"

$ zip -r bar foo/*
  adding: foo/[Content_Types].xml (deflated 75%)
  adding: foo/_rels/ (stored 0%)
  adding: foo/_rels/.rels (deflated 61%)
  adding: foo/docProps/ (stored 0%)
  adding: foo/docProps/app.xml (deflated 48%)
  adding: foo/docProps/core.xml (deflated 52%)
  adding: foo/word/ (stored 0%)
  adding: foo/word/_rels/ (stored 0%)
  adding: foo/word/_rels/document.xml.rels (deflated 71%)
  adding: foo/word/document.xml (deflated 66%)
  adding: foo/word/fontTable.xml (deflated 77%)
  adding: foo/word/settings.xml (deflated 62%)
  adding: foo/word/styles.xml (deflated 89%)
  adding: foo/word/stylesWithEffects.xml (deflated 89%)
  adding: foo/word/theme/ (stored 0%)
  adding: foo/word/theme/theme1.xml (deflated 79%)
  adding: foo/word/webSettings.xml (deflated 42%)
$ mv bar.zip bar.docx
$ open bar.docx

Nope!

Aargh! So what's the secret? Here's the secret: cd into the directory first, then build your zip archive outside the directory. Here we cd into foo and make bar.zip in the directory above, then rename it to bar.docx.

$ cd foo
$ zip -r ../bar *
  adding: [Content_Types].xml (deflated 75%)
  adding: _rels/ (stored 0%)
  adding: _rels/.rels (deflated 61%)
  adding: docProps/ (stored 0%)
  adding: docProps/app.xml (deflated 48%)
  adding: docProps/core.xml (deflated 52%)
  adding: word/ (stored 0%)
  adding: word/_rels/ (stored 0%)
  adding: word/_rels/document.xml.rels (deflated 71%)
  adding: word/document.xml (deflated 66%)
  adding: word/fontTable.xml (deflated 77%)
  adding: word/settings.xml (deflated 62%)
  adding: word/styles.xml (deflated 89%)
  adding: word/stylesWithEffects.xml (deflated 89%)
  adding: word/theme/ (stored 0%)
  adding: word/theme/theme1.xml (deflated 79%)
  adding: word/webSettings.xml (deflated 42%)
$ cd ..
$ mv bar.zip bar.docx
$ open bar.docx

Presto! The .docx file opens up in Word with no corruption.

References:

[ Submitted by John on Fri, 2011-02-04 16:07. | | ]

Solution to SAS 9.2 Installer Crashing on Windows 7 on VMWare Fusion

When installing SAS on Windows 7, typically you'd right-click on setup.exe and choose Run as Administrator, watch the SAS Deployment Wizard come up and the blue progress bar start moving. But! Then Windows 7 suddenly says "Console Window Host has stopped working." and offers to close the program. The Deployment Wizard may run for a while longer and silently disappear.

The entry in the Windows Application Log is not much help; it just says "Event 1000, Application Error: Faulting application name: conhost.exe".

The reason this is happening is that the SAS installer is trying to write to a temp file. Because you have VMWare Fusion set up to share folders between the Mac and the PC, when the installer tries to write a log file VMWare Fusion denies it, and the installer freaks out and dies.

The solution is:

  1. Shut down your virtual machine.

  2. Turn off "Share folders on your Mac" in the virtual machine settings.
  3. Start your virtual machine back up.
  4. Run the installer with no problems.
  5. Turn sharing back on again once SAS is installed.

Reference:
http://www.mathkb.com/Uwe/Forum.aspx/sas/47604/SAS-Mac-VMWare-Fusion

[ Submitted by John on Wed, 2010-12-15 10:31. | | ]

Using Mac OS X 10.6 to Create a Bootable FreeBSD 8.1 Installer on a USB Memory Stick

Warning. Follow these instructions at your own risk. I am not responsible when you use dd to blow away your kitty pictures.

Download the FreeBSD 8.1 memory stick image from a FreeBSD repository. I picked one from here.

Plug in your USB stick. OS X will mount it.

You want to unmount the volume while keeping the drive available. To do this, open Disk Utility, click on the name of the mounted volume, and click the Unmount button.

Now you need to know the disk's identifier. You can find this out by right-clicking the disk in Disk Utility. The disk identifier of my USB stick was disk4.

Finally, copy the memory stick image onto the memory stick, substituting the disk identifier into this terminal command. if means "in file" and of means "out file".

dd if=/path/to/freebsd.img of=/dev/diskidentifier bs=10240 conv=sync

So the commands I issued looked like this (yours will be different, since your disk identifier will be different).

dd if=/Users/john/Downloads/FreeBSD-8.1-RELEASE-amd64-memstick.img of=/dev/disk4 bs=10240 conv=sync

When it's done, dd says:

105018+0 records in
105018+0 records out
1075384320 bytes transferred in 1310.732002 secs (820446 bytes/sec)

That's 22 minutes.

Back to Disk Utility. Select the memory stick. Click the Eject button. Now go boot FreeBSD!

[ Submitted by John on Fri, 2010-10-08 17:01. | | ]

Installing BioPerl on Mac OS 10.6 Snow Leopard in 6 Easy Steps

The strategy I used to install BioPerl was as follows:

1. Use MacPorts to install Perl.
2. Use CPAN to install BioPerl.

Here are the nitty gritty details. You need a live internet connection, as both MacPorts and CPAN expect to be able to download packages.

Step One: XCode Tools

Before MacPorts can be installed, XCode Tools needs to be installed. This is free from Apple and can be installed from the original OS X 10.6 DVD or downloaded from Apple's developer site.

You can tell that XCode Tools is installed by looking for a Developer directory at the root of your hard drive.

Step Two: MacPorts

I simply downloaded the MacPorts Package Installer from the MacPorts site.

Step Three: Install Perl

sudo port install perl5.12

Step Four: Install GraphViz

This is a prerequisite of BioPerl and the BioPerl build will fail if it is not installed. It will download a ton of prequisites first. After typing the following, get a coffee and a sandwich.

sudo port install graphviz

Step Five: Configure CPAN

CPAN likes to have YAML installed. So:

sudo cpan YAML

At this point cpan will realize it's being run for the first time and ask you some questions like

Would you like me to configure as much as possible automatically? [yes]

Selecting the defaults worked fine.

It's nice to have LWP too.

To install LWP, first get to the cpan command prompt:

sudo cpan

Then install it:

install Bundle::LWP

Step Six: Build BioPerl

To install BioPerl, first get to the cpan command prompt:

sudo cpan

At the command prompt, tell CPAN that you want it to automatically get and install any prerequisites it comes across (this saves you hours of choosing "Yes"):

cpan[1]> o conf prerequisites_policy follow

And now, at the cpan prompt, install BioPerl:

install C/CJ/CJFIELDS/BioPerl-1.6.1.tar.gz

It will stop several times along the way. Except for the following question where my selection was to install all optional external modules, the defaults were fine.

Install [a]ll optional external modules, [n]one, or choose [i]nteractively? [n] a

During the tests that BioPerl runs, I saw the following:

Replacement list is longer than search list at Bio/Range.pm line 251.

According to this post, The above are warnings from perl 5.12 that can be ignored (they have been fixed in bioperl-live on github).

For a quick test of BioPerl, put the following into a file named test.pl:

use Bio::Perl;
# this script will only work if you have an internet connection on the
# computer you're using, the databases you can get sequences from
# are 'swiss', 'genbank', 'genpept', 'embl', and 'refseq'
$seq_object = get_sequence('embl',"AI129902");
write_sequence(">roa1.fasta",'fasta',$seq_object);

Then run it:

perl test.pl

and sure enough, a file named roa1.fasta gets written. Yay!

If you are installing BioPerl on a Mac that has multiple user accounts, you'll need to make sure that the following exists in each user's .profile file (at /Users/john/.profile, for example):

# MacPorts Installer addition on 2010-10-04_at_15:32:08: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

This makes it so that when you type perl the Mac will find and use the Perl from MacPorts instead of the system Perl. Also, be aware of scripts that say #!/usr/bin/perl at the top.

[ Submitted by John on Thu, 2010-10-07 11:23. | | ]

Solution to 100% CPU Usage by Linux Guest on VMWare Fusion

As part of my testing setup, I have an Intel Mac Pro with Mac OS X 10.6 Server (which runs with the 64-bit kernel) on which I run VMWare Fusion 3.0.1 and several Red Hat virtual machines.

I noticed that even at idle, each VM was taking up a high amount (like 100%!) of a CPU core. Additionally, on one VM top was displaying in near-real-time, which was kind of neat but I doubt the intended behavior. Because of this, I suspected the time management in the kernel was off.

Sure enough, Timekeeping Best Practices for Linux Guests has some hints, and for more information than you'll ever want, try Timekeeping in VMWare Virtual Machines (I was particularly interested in the Clocksource Kernels section).

Making the following modification to /etc/grub.conf on RHEL5 brought my CPU usage down from 100% to barely noticeable:

Before:

kernel /vmlinuz-2.6.18-164.11.1.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet

After:

kernel /vmlinuz-2.6.18-164.11.1.el5 ro root=/dev/VolGroup00/LogVol00 rhgb divider=10

I took out quiet because I like to see what's happening when the system boots.

The Note on RHEL 5.4 or CentOS and divider=10 mentions that you do not need this for RHEL 5.4 for accurate timekeeping, but you do need it to prevent the excessive CPU use.

I also modified /etc/ntp.conf as described in the above article, adding

tinker panic 0

to the top of the file and commenting out the following lines:

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
#server 127.127.1.0
#fudge 127.127.1.0 stratum 10

My VMs are down from 100 percent CPU use to practically zero. Think of the energy savings!

[ Submitted by John on Fri, 2010-02-12 11:35. | | ]

APC UPS and Snow Leopard Server Not Communicating

I have used APC (American Power Conversion) power equipment for a long time. I have had both good and bad experiences with their products (a cherished memory is calling their technical support and asking about the "smell of burning plastic" emanating from one of their units).

I've recently upgraded an Intel Mac Pro to Snow Leopard Server (OS X Server 10.6.2) and noticed that the controls in Energy Saver for the UPS are different. Not in a good way.

Here's the relevant screen from OS X Server 10.5.8:

And the same screen from OS X Server 10.6.2:

After reading a thread on Apple's support site about APC UPS Charge Percentage Not Updating I changed the setting on the server to that shown in the second screenshot above; namely, since the computer can't seem to read the charge percentage, it's better to let the computer monitor how long it's been on the battery.

Another annoyance is that I keep getting the dialog Your computer is now running on UPS backup battery power. The UPS is supposed to self-test every 14 days but I'm seeing the dialog more often then this.

It makes me uneasy, and I don't like being uneasy about servers.

See also: http://www.macworld.com/article/140207/2009/05/apc_leopard.html

[ Submitted by John on Mon, 2009-12-14 11:22. | | ]

Eudora, Snow Leopard and Kerberos

I upgraded to OS X 10.6 "Snow Leopard" yesterday. A smooth upgrade except for one thing.

Eudora 6.2.4 for Mac OS X works on 10.6 (provided the optional Rosetta PowerPC-emulation code is installed), but not with kerberos.

To use kerberized POP, Eudora depends on the Code Fragment Manager library "Kerberos" which is part of the MIT Kerberos Extras for OS X package.

The actual library is installed to /System/Library/CFMSupport/Kerberos and is a 983k file last updated in 2003. It's labeled version 4.2.

If the MIT Kerberos Extras for OS X have been installed, and thus this library is installed, Eudora will fail to launch with the following errors:

Launch failed with error code -2821 (cfragInitFunctionErr) for application /System/Library/Frameworks/Carbon.framework/Versions/A/Support/LaunchCFM App

Eudora can be launched by removing the library. But then kerberos-enabled POP cannot be accomplished.

[ Submitted by John on Tue, 2009-09-01 10:55. | | ]

Programmatically suspending, quitting, and resuming Parallels Desktop for scheduled backup

I wanted to do automatic scheduled backups with the awesomely amazing SuperDuper!. The computer to be backed up was a Mac Mini running Mac OS X 10.5 Leopard. But the problem was that Parallels Desktop was running all the time. And everyone knows that when you try to back up open files that may be changing, Bad Things Happen.

"No problem," I thought. Since SuperDuper! allows you to run a script before and after a scheduled backup (have I mentioned how brilliant SuperDuper! is?) I'll use a script to suspend the virtual machine before the backup, and resume it afterward.

SuperDuper! with shell scripts assigned

So I fired up Script Editor and went to open up Parallels Desktop's AppleScript Dictionary.

Uh.

Apparently Parallels Desktop does not implement AppleScript.

I was stymied until I remembered something that the indefatigable Matt Neuburg had written in AppleScript: The Definitive Guide, Second Edition in a chapter titled Unscriptable Applications. The approach is to cheat by using the Accessibility API built into Mac OS X. From there you can direct mouse clicks, radio button selection...in short, all sorts of mayhem. "Aha!" I thought. "I'll just direct Parallels from the Accessibility API! Sort of like the puppeteer in Being John Malkovich."

First I made sure that accessibility was enabled by going to the Universal Access preference pane in System Preferences.

Enable assistive devices

Then I made a shell script for SuperDuper! to run before backup. Here's the script:

#!/bin/sh
osascript /Users/john/suspendparallels.txt
sleep 35
osascript /Users/john/quitparallels.txt
sleep 10

The shell script first executes the suspendparallels.txt AppleScript to suspend the virtual machine:

-- Suspend a Parallels virtual machine.
-- Assumptions:
--  - only one virtual machine is running
--  - the "Enable access for assistive devices" checkbox is checked in the Universal Access control panel
-- Tested on Mac OS X 10.5.7 with Parallels Desktop 4.0.
-- John VanDyk 7/22/2009
tell application "Parallels Desktop" to activate
tell application "System Events"
  tell application process "Parallels Desktop"
    tell menu "Virtual Machine" of menu bar 1
      click menu item "Suspend"
    end tell
  end tell
end tell

Then the shell script waits for 35 seconds (enough time for the virtual machine to be written to disk), and executes the quitparallels.txt AppleScript:

-- Quit Parallels.
-- Assumptions:
--  - only one virtual machine is running
--  - the "Enable access for assistive devices" checkbox is checked in the Universal Access control panel
-- Tested on Mac OS X 10.5.7 with Parallels Desktop 4.0.
-- John VanDyk 7/22/2009
tell application "Parallels Desktop" to activate
tell application "System Events"
  tell application process "Parallels Desktop"
    tell menu "Parallels Desktop" of menu bar 1
      click menu item "Quit Parallels Desktop"
    end tell
  end tell
end tell

"But John," I can hear you asking, "why not put these together into one simple AppleScript and just use 'delay 35' to create the pause?" I'll tell you why. Because when you do it that way it doesn't work. Plus I got a scary error about "class released with no pool in place - just leaking". Seriously. So I figured, since AppleScript is always, well, flaky for me, I'd just put as much as I could in the shell script and call out to AppleScript only when necessary.

All right. So now SuperDuper! can clone the drive since the Parallels Desktop Windows XP virtual machine has been suspended and the program has been closed. But what about afterwards, when we want to bring Parallels Desktop up just like it was? Turns out, that's even easier. Here's the shell script that SuperDuper! runs after it completes the copy:

#!/bin/sh
osascript -e 'tell app "Parallels Desktop" to activate'
sleep 10
osascript /Users/john/resumeparallels.txt

That first osascript call is actually launching Parallels Desktop. We give it 10 seconds to launch, which is plenty.

Fortunately it launches with the suspended virtual machine. All we have to do is tell it to resume. Here's resumeparallels.txt:

-- Resume a Parallels virtual machine.
-- Assumptions:
--  - only one virtual machine is running
--  - the "Enable access for assistive devices" checkbox is checked in the Universal Access control panel
-- Tested on Mac OS X 10.5.7 with Parallels Desktop 4.0.
-- John VanDyk 7/22/2009
tell application "Parallels Desktop" to activate
tell application "System Events"
  tell application process "Parallels Desktop"
    tell menu "Virtual Machine" of menu bar 1
      click menu item "Resume"
    end tell
  end tell
end tell

Presto! It works.

[ Submitted by John on Wed, 2009-07-22 13:07. | | ]

Negative deletion

I'm confused...does this mean Leopard is actually creating files?

[ Submitted by John on Wed, 2009-07-08 15:05. | | ]