![]() |
launchd WatchPaths not triggered by CGI file change
I have a Launch Agent watching a directory (WatchPaths). When a file is added, removed, or altered by user interaction, the Agent is triggered. However, I need it to be triggered by updates being made by a CGI script -- which it is not currently doing.
|
What version of Mac OS X? Tiger or Leopard? Server or Client?
|
Hi Mikey-San. It is:
Intel Mac Mini 2.0 Mac OS X 10.4.10 Client |
It might be due to it being a LaunchAgent as opposed to a LaunchDaemon.
As I recall, there were various problems with the former in Tiger. I don't think they ever really worked quite right from what I recall reading. So try making it a LaunchDaemon instead. |
Can I make it a LaunchDaemon just by moving it to /Library/LaunchDaemons, or is there more to it?
|
http://developer.apple.com/macosx/launchd.html
http://developer.apple.com/documenta...01791-BBCBHBFB Quote:
|
Agents run for specific users, or when users log in, so you can toss it in /Library/LaunchAgents or ~/Library/LaunchAgents
If you want it to run at start up regardless put it in /Library/LaunchDaemons To make sure your launchd item is running you can invoke this command sudo launchctl list if your plist item is listed then its running |
OK, I've tried it in:
/~Library/LaunchAgents This worked most consistently, but didn't acknowledge changes made by CGI. /Library/LaunchAgents Also didn't acknowledge CGI. /Library/LaunchDaemons This only worked when I trashed a file. /System/Library/LaunchAgents Also didn't acknowledge CGI. /System/Library/LaunchDaemons Also didn't acknowledge CGI. Here's the basic XML I'm working with: Code:
<?xml version="1.0" encoding="UTF-8"?> |
is your launchd item even running? Have you verified that?
|
Quote:
|
Quote:
Does it trigger the Agent? Are you sure that watching a folder is supposed to trigger upon changes to the content of files in that folder? (I haven't looked up the documentation.) Maybe when you alter the file via "user interaction" you are actually deleting and recreating the file - that is the way that a lot of text editors work for example - but that your CGI script keeps the same file but alters it. Consider running 'sudo fs_usage | grep name_of_your_file' and looking at what operations are being done in the two cases. |
if his paths are right Hayne, the ondemand switch in the plist should keep the launchd item always monitoring that path.
Just curious what is the ownership of your launchd plist file? Is it owned by root:wheel or by localadmin:admin? I have had issues in the past with launchd items and 10.4 if it wasn't owned by root. Here go some official guide lines from Apple on the subject Quote:
|
OK, I ran the command you suggested, and accessed the file from the Finder and edited it in TextEdit (you can see rsync come up in the log). Then I accessed it from the CGI.
Code:
//Accessing in Finder |
Quote:
|
Quote:
|
Quote:
I just tried editing that file again through the CGI. It worked once, triggering the rsync script; then it failed to trigger it subsequent times. What does it mean?! |
I don't see 'root' in the list of ownership options. Am I missing something?
|
If you tossed the plist in /Library/LaunchAgents this simple command will tell owner:group
Code:
ls -al /Library/LaunchDaemons | grep com.mydaemon.plist |
Here's what it said:
-rw-r--r-- 1 root wheel 587 Mar 14 15:24 com.mdc.mylaunchdtest.plist |
Ok, its owned by root:wheel so that looks good, that was just a guess and an issue I had ran into in the past....
|
Should it be executable or anything?
|
Quote:
domain.mycompany.plist for example |
Quote:
I notice for 10.5 that the onDemand has been deprecated Quote:
Quote:
|
I am not familiar with CGI scripts, but I get the impression that the script is modifying a file rather than moving files, Is this correct?
When I test a folder that is being watched, it will trigger if a file is moved To or From its path, but will not trigger if a file has been updated/modified This appears to be the intended behaviour for watchPaths. *edit* Maybe adding something like this to the end of the script.. Code:
mv /Users/username/Desktop/foo_folder/foo.txt /Users/username/Desktop/foo_folder/mvFolder/foo.txt;mv /Users/username/Desktop/foo_folder/mvFolder/foo.txt /Users/username/Desktop/foo_folder/foo.txt |
Quote:
|
Quote:
|
There's also a binary at /bin/wait4path which should provide the same (or similar) action. [see man wait4path]
From a very limited test last night, mine seems to stay asleep forever (well, longer than I felt like waiting). -HI- |
Quote:
Code:
#! /bin/sh |
Quote:
|
I was thinking, maybe an approach could be to to have one watchpath to look at the folder. when a new file is added it writes the path of the new file to a second watchpath which watches the files.
The second one should then trigger on changes the the file. I have tested parts of this idea and it seems it would work. The write part is the easy bit, Code:
defaults write ~/Library/LaunchAgents/watchpath "WatchPaths" -array-add '<string>/Users/username/Desktop/foo_folder/foo.file</string>' |
mark -- that's awesome. I tested watching the individual file, rather than the folder as I had been, and it does trigger launchd when the CGI edits the file. Keep me posted, and I'll research a solution, too.
|
This is the code I have been working on, to add into the (folder) watchpath plist.
Code:
#!/bin/bash*Note, I only have a small amount of knowledge of shell. **edit 1** Changed the find part to ignore hidden files **edit 2** added to the script, to cope with spaces in filenames. Also I have now tested this and it works. The folder watching watchpath plist calls this shell script when a new file is added. The shell in turn checks against the paths in the file watching watchpath plist and adds any that are not already in it. |
Looks good. I'll set set up a sandbox account and try it out later.
Thanks for your help, everybody! |
| All times are GMT -5. The time now is 05:44 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.