[launchd-dev] General questions on launchd

Scott Haneda talklists at newgeo.com
Mon Jun 1 11:29:17 PDT 2009


Hello, first post, I have done my best to hit up nabble archives and  
see if there are any answers, so far, no luck.  I am on 10.5.

Where does one draw the line from stuffing a command into a plist  
versus having a simple command call a more complicated script, even if  
the script to be called is not that complicated?

Example:
<dict>
	<key>ProgramArguments</key>
	<array>
		<string>/bin/bash /Users/me/Library/Application\ Support/dir/script</ 
string>
	</array>
</dict>
</plist>

* How important is it to use full paths to binaries like `echo` and  
`ls`, as long as I am sure that I have not mucked with the environment  
variables to them?  Are environment variables cleared in launchd, or  
do user launchd plists need to have care taken to make sure an alias  
bash alias will get in the way?

I have never been able to get that to work.  syslog tells me
Jun  1 11:02:47 host com.apple.launchd[155] (com.me.foo[19809]):  
posix_spawnp("/Users/me/Library/Application Support/dir/script", ...):  
No such file or directory
Jun  1 11:02:47 host com.apple.launchd[155] (com.me.ALARM[19809]):  
Exited with exit code: 1

I try to work around it with things like this:
<dict>
	<key>ProgramArguments</key>
	<array>
		<string>cd</string>
		<string>/Users/me/Library/Application\ Support/dir/;</string>
		<string>./script</string>
	</array>
</dict>

Those generally fail as well.  It seems to be spaces in the path name,  
but there has to be a way to make spaces work. Application Support is  
a perfect place for me to store my scripts, and logs from those  
scripts, so far, no luck.  Pipes are also an issue, or redirection,  
which I have not been able to get around.  A basic echo "test" >>  
log.txt or one with a real | in it also do not work for me.

A lot can be done in a short one liner as well, what is the trick,  
what are the limits?

I generally just stuff all my code into a script, ~/bin is usually  
where I put it, and have launchd call it as /bin/bash /Users/me/ 
scriptname

I seem to have a lot of trouble unloading items.  There are cases  
where I have tested, and then deleted a plist, forgot to unload it.   
If I try to unload it, I of course have no file to point to, so I try  
to unload it by name.  Neither works.

I have ended up rebooting, but consider sending a HUP to launchd, but  
ps shows there to be a few more items in the list than I feel safe  
just restarting.

Can someone also point me to docs or explain to me the  
'WorkingDirectory' item.  I al always cd'ing to a location where I do  
my work.  I do not mind continuing to do that, but if defining  
'WorkingDirectory' in a plist does what I think it does, it would be  
nice to have, as only a trigger to the person debugging it as to where  
the work is happening, without having to trace a ton of scripts  
calling each other.

Thank you.
-- 
Scott * If you contact me off list replace talklists@ with scott@ *



More information about the launchd-dev mailing list