Join 3,512 readers in helping fund MetaFilter (Hide)


launchd WatchPaths vs RuntimeRevolution CGI
March 14, 2008 1:02 PM   Subscribe

Can a launchd plist set to WatchPaths respond to a CGI script updating a file?

I have a shell script in ~/ that runs rsync between a local folder and a remote server directory. The .ssh/authenticated_keys file has been updated, so this whole process works smoothly without any user interaction.

I wanted this script to run automatically, so I set up a plist for launchd to watch the local folder, and respond to changes by running the rsync script. So, whenever a file is moved in or out of the local folder, or a file is updated by the user, rsync is launched, and the remote server is updated to reflect the changes. This also works fine.

Here's where it all goes awry:

The actual files that I want launchd to watch for updates will be updated by a CGI script. The script has been working fine for years, and the Finder reflects the new modification date when a file is changed by the script. However, launchd doesn't seem to notice the file being modified by the script.

I've tried moving the plist among the various Agent and Daemon folders (loading it with Lingon or the launchctl command), with no luck.

Ideas?

Intel Mac Mini 2.0
Mac OS X 10.4.10
posted by evil holiday magic to Computers & Internet (4 answers total)
 
What is launchd dumping to the logs? Is it getting any errors in debug mode?
posted by onalark at 1:21 PM on March 14, 2008


Also, who is the CGI script running as? Is there a reason the CGI script can't just launch the rsync script on its own?
posted by onalark at 1:27 PM on March 14, 2008


onalark - The logs aren't saying anything about launchd when the CGI updates the file. I'll look into your suggestion about the CGI running rsync, though I'd prefer the processes be distinct.
posted by evil holiday magic at 1:58 PM on March 14, 2008


I don't know anything specific about launchd, so what follows is more of an educated guess than anything else.

In Unix, if I remember correctly, file modification dates are kept in the file's inode - not in the directory entries that point to that inode. This means that if you've got a single file hardlinked into two different directories, and you change the mod date on the file by opening it from either place, you will see the change appear in both directory listings.

But the point is that the directories themselves are not changed by changing the mod dates on the files listed inside them. So if some process is watching a directory inode for changes, it's not going to see any when one of that directory's linked files is written to, unless it's also watching all the inodes for all the files inside that directory.

I'm guessing that launchd doesn't do this, probably for performance reasons. I'm guessing that when you tell launchd to watch a file for changes, it will monitor only that file's inode, and that this will be so whether the file is a regular file or a directory.

Note that adding a file to a directory, unlinking a file from a directory, or renaming a file inside a directory will cause the directory file itself to be written, and the mod time within its own inode to be correspondingly updated. I'd expect any of these operations to trigger a launchd watch on that directory.

You might try keeping a zero-length file called something like "cgi-mod-count-10473" inside any folder your cgi script can write to, and having the script rename that file by incrementing the number part of its name (or create the file if it doesn't exist) right after it makes a change to any other file in that folder. If I'm right, that will trigger launchd just nicely.
posted by flabdablet at 12:49 AM on March 15, 2008


« Older I'm looking for recommendation...   |  What's the best way to get a f... Newer »
This thread is closed to new comments.