[launchd-dev] fork & exit in Shell Script (Revisited)
Charles Darwin
DarwinsKernel at gmail.com
Mon Nov 10 10:13:11 PST 2008
On Nov 10, 2008, at 9:35 AM, Quinn wrote:
> At 13:56 -0500 5/11/08, Charles Darwin wrote:
>> What is the proper way of shutting down a daemon? Another daemon
>> that runs a bit later?
>
> OK, I'm really confused )-:
>
> Let's start by agreeing on terminology. I'm using the terms from
> TN2083. Please familiarise yourself with them (specifically
> "daemon", "agent" and "background program").
>
> <http://developer.apple.com/technotes/tn2005/tn2083.html>
>
> If your background program is a "daemon" it is, by definition, not
> running on behalf of a specific user.
Then I have got the definition wrong. Since my script doesn't have
any GUI I thought it would be a daemon. But I'm getting the felling
that that is not the right criteria.
Now lets call it and "agent", then according to what we have here:
<http://developer.apple.com/macosx/launchd.html>
I should be able to put the plist file into "personal LaunchAgents
directories of specific users". I assume that would be ~/Library/
LaunchAgents (or at least that's what the man page for launchd reads):
> And thus it should not be affected by users logging in and out.
It is affected (taking it to be a daemon) and here is why. Here is
the script:
#------------------
#!/bin/sh
if [ ! -d "/Volumes/tutorial" ] ; then
/bin/mkdir -p /Volumes/tutorials && /sbin/mount_afp afp://
url/tutorials/ /Volumes/tutorials/
fi
if [ ! -d "/Volumes/home" ] ; then
/bin/mkdir -p /Volumes/homes && /sbin/mount_afp afp://url/
homes/ /Volumes/homes/
fi
#------------------
When user logs out OS X ejects the mounted afp volumes (tutorials &
homes in the example above).
Now lets again call it an agent so I can use ~/Library/LaunchAgents
(Per-user agents provided by the user) to launch my script whenever
that particular user logs in. Well it just sits there and does
nothing. The plist is loaded however:
$ launchctl list
<label>
$
Here is the plist by the way:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>label</string>
<key>ProgramArguments</key>
<array>
<string>/Users/user/.scripts/mount_tut</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
>
> Furthermore, when you started talking about
>
>> /Users/user/Library/LaunchDaemons/<label>.plist
>
> I got even more confused because launchd doesn't load launchd
> daemons from the user's home directory.
True. But as I asked before should it handle agents from ~/Library/
LaunchAgents?
Thanks again for helping me with this Quinn.
Charles
>
> Can you give me a quick overview of the what you want your
> background program to do? I'm specifically interested in the
> context in which the process should run and its expected lifecycle.
>
> S+E
> --
> Quinn "The Eskimo!" <http://www.apple.com/
> developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/
> Hardware
> _______________________________________________
> launchd-dev mailing list
> launchd-dev at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev
More information about the launchd-dev
mailing list