POE Palm Sync Monitor

I am weird.

i have a Motorola Droid and a first generation iPhone which I use on WiFi only. But I really can't get myself to use either of them for task management.

Nothing beats the feel of my Palm Tungsten C keyboard. And nothing really beats the simplicity of the Palm ToDo List. Well, not really nothing, but you know what I mean.

I was surprised and happy to notice active development still taking place on p5-Palm. Today, I decided to resurrect an old project I had started to create a Palm Sync daemon on my home server.

First, I confirmed that pilot-link was up and running on my server. Next, I refreshed my memory on the commands used to run a WiFi sync.The first step is to make sure the user of the Tungsten C and the user of pilot-link are one and the same. This overwrites the user on the device, so proceed with caution.

pilot-install-user -p net:any -i 1000 -u mike

After setting the user, make a full backup of the device, where 'backup' is a directory.

pilot-xfer -p net:any -b backup

You may need to include an exclude file list using '-e exclude.txt', where 'exclude.txt' is a file containing the Palm files to exclude from a backup (or a sync). When I first tried this, I ran into 'Segmentation fault' errors during backup. An upgrade to pilot-link-0.12.0-pre4 did nothing to alleviate the problem. I had to exclude the file (ImgFile-Foto.prc) causing the segmentation fault from the back up process (see http://www.jpilot.org/pipermail/jpilot/2005-January/004609.html).

Finally, you can sync the device like so:

pilot-xfer -p net:any -s backup

Now I needed a way to keep my pilot-xref sync process running on my server until Kingdom Come. In the end, I decided to turn to an old trusty friend for help in this matter, POE.

I knew I needed something to monitor the sync process running on my server to determine if the sync process was up and listening for my Palm or if it needed to be started. Because I am not the sharpest tool in the shed, my first impulse was to hack together something that parsed the output of ps -ef. Then someone on #perl on Freenode reminded me that it's rarely wise to write something that parses text meant for human consumption. mst was kind enough to point out Proc::ProcessTable. This would easily match the name of my sync command in the process table to let me know if my script was running or not. But before cobbling this together, I took one more tour through the glorious CPAN and stumbled upon POE::Component::Supervisor::Supervised::Proc. Although not very aptly named, this module was to do the trick, very easily.

#!/usr/bin/perl
use warnings;
use strict;
use POE;
use POE::Component::Supervisor;
use POE::Component::Supervisor::Supervised::Proc;
my $program = "pilot-xfer -p net:any -s backup";
POE::Component::Supervisor->new(
    children => [
        POE::Component::Supervisor::Supervised::Proc->new(
            program => [$program],
            restart_policy => "permanent",
        ),
    ],
);

Sometimes the hardest part of programming is finding out what things are called on CPAN.

1 Comment

I loved my Tungsten T!

Leave a comment

About initself

user-pic Perl is better than sliced bread. Way better.