Why is my 'launchd' task not responding to changes in watched files?
FWIW I tried it here and it seems to be working for me. Any time I manually appended something to /Library/Logs/CrashPlan/history.log.0 the script did get triggered.
As such, this isn't really an answer, but it’s more a series of tips for debugging launchd
:
A few tips for diagnosing launchd:
1) Use the stdout
and stderr
paths and see if anything gets logged to them. You can do that by adding these lines to your com.crashplan.status.plist
file.
<key>StandardErrorPath</key>
<string>/tmp/com.crashplan.status.stderr.log</string>
<key>StandardOutPath</key>
<string>/tmp/com.crashplan.status.stdout.log</string>
(If multiple people use the same Mac, you might want to use a different path than /tmp/ but if it’s only you then it is as good of a place as any.)
2) With #1 you might also want to adjust your script (/Users/Rax/Library/Automation/Shell/crashplan_status) to include debugging info such as when it started and when it finished. That can be as simple as something like this added near the top of the script:
echo "$0: started at `date`"
and something like this near the end
echo "$0: finished at `date`"
3) With #2 you might also want to use something like terminal-notifier to show you when your script is being called, at least until you get past the debugging stage.
4) If none of that helps, you should check the exit status of whatever commands that you are calling in crashplan_status
and see if those are exiting properly. For example, let's say that you were running echo
in your crashplan_status
5) Is your environment in launchd
different from your shell in some way? This is best verified by adding this line near the top of your launchd script:
/usr/bin/printenv | /usr/bin/open -ef
which will cause the printenv
to be sent to the stdout and the results opened in TextEdit.
The most common 'environment' problem that I run into is not having the $PATH set properly for launchd. It’s usually set in your shell init files such as .bashrc and inherited by any shell scripts you run from Terminal, but won't be for launchd
.
You can see the path that launchd
is using by:
launchctl getenv PATH
If you want to set it, you can set it by
launchctl setenv PATH
for example, for my system it would be:
launchctl setenv /Users/luomat/Dropbox/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
If you don't want to have to remember to set that every time you start your computer, you can add it to /etc/launchd.conf
by adding a line this:
setenv PATH /Users/luomat/Dropbox/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
obviously change that to match your system. Also, don't be surprised if /etc/launchd.conf
doesn't exist on your system. You may have to create it. To do that, I recommend a simple:
sudo pico -w /etc/launchd.conf
and when you are done editing, press control + X and follow the prompts to save the changes.