Log in

No account? Create an account
entries friends calendar profile my webpage Previous Previous Next Next
Geekiness. - Tina Marie's Ramblings
Red hair and black leather, my favorite colour scheme...
I need to write a daemon (RHEL4).

I want to have a daemon that watches a set of directories, and does something with xml files it finds there. The first version will just put pictures into a database, but eventually, I'd like to tie it into the adminPortal.

Bonus points if it can be signaled on a port to go do it's thing, otherwise I'll run it on a timer.

I know nothing at all about this. Has anybody done it (that's mostly in your direction, alioth1 and popefelix)? Can somebody point me at a book? I didn't see an O'Reilly book that looked anything like "Daemon Programming For Linux".

Help could possibly be rewarded with a box of chocolate-chip cookies.


11 comments or Leave a comment
ptomblin_lj From: ptomblin_lj Date: August 9th, 2006 04:13 pm (UTC) (Link)
You don't anything special. Use inotify and you can shell script it.
ptomblin_lj From: ptomblin_lj Date: August 9th, 2006 04:34 pm (UTC) (Link)
skywhisperer From: skywhisperer Date: August 10th, 2006 12:43 am (UTC) (Link)
Hm. RHEL 4 doesn't support inotify. The question is, do I feel lucky enough to patch the kernel?

Thanks! If nothing else, it pointed me to dnotify, which is less then optimal, but I'm only going to monitor one or two directories, so it won't be too bad.
ptomblin_lj From: ptomblin_lj Date: August 10th, 2006 01:05 am (UTC) (Link)
We are using dnotify right now, but are moving to inotify because dnotify doesn't do a good job on file modifications.
skywhisperer From: skywhisperer Date: August 10th, 2006 01:14 am (UTC) (Link)
I don't care about file changes - I just care about directory changes. I want to be able to upload an XML file into a directory and have it be processed.
ptomblin_lj From: ptomblin_lj Date: August 10th, 2006 01:27 am (UTC) (Link)
Word to the wise about dnotify: If you possibly can, arrange to have the files go into a different directory than the one you're watching (but on the same file system), and then move it in when it's done. Or have them write in file name different from the ones you're looking for, and renaming when they're done (rsync does it that way). Otherwise your script gets started when the file is still getting written. We had to add logic to check if the file was updated in the last 5 seconds, and if it had, then to sleep for 5 seconds again.
skywhisperer From: skywhisperer Date: August 10th, 2006 03:22 am (UTC) (Link)
That is really good to know, since these are going to be certainly multi-meg files, and possibly multi-gig.
(Deleted comment)
skywhisperer From: skywhisperer Date: August 10th, 2006 03:25 pm (UTC) (Link)
Thank you. :)
alioth1 From: alioth1 Date: August 9th, 2006 06:05 pm (UTC) (Link)


Paul mentioned inotify (which is the best one to use, since it works with the kernel) however, I don't think the support for inotify is in 2.6.9 (which is what RHEL4/CentOS4 use, unless RedHat backported it). I could be wrong so it's worth checking just in case - but I think you'll probably have to patch the kernel (or perhaps build a kernel module) for inotify to work.

If you don't feel like patching the kernel, use dnotify instead. A dnotify package is available for RHEL 4 on the DAG Apt/Yum repository (http://dag.wieers.com/home-made/apt/) - also known as rpmforge. You can just download the RPM from searching for it in "Package overview" on that site, or add the DAG repository to your system (which is a very good idea - LOTS of useful packages for RHEL 4, and adding the repo gives you automatic dependency resolution).

The difference between inotify and dnotify is inotify works with kernel support and doesn't keep a file descriptor open on the directory you're watching. Dnotify does keep an FD open. The drawback of dnotify vs inotify is if you're watching many directories, this means lots of file descriptors open, and it also may mean you can't umount the device when you want -- but I doubt either are a problem for you. So if inotify requires a kernel patch on your system I'd suggest just go with dnotify.

Disclaimer: I've never done more than read the manpage for dnotify a couple of years back...
skywhisperer From: skywhisperer Date: August 10th, 2006 12:44 am (UTC) (Link)

Re: dnotify

I think that's the answer. Thank you!

I owe you cookies. You can pick them up next time you're here. :)
11 comments or Leave a comment