Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

First off: Im absolutely new to Mac, so the problem might be really really basic.

I have been trying to set up a Launchd Daemon to run at startup to run a Service via Mono.Frameworks. I used Lingon to create the .plist file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.netviewer.WorkerContainer</string>
<key>ProgramArguments</key>
<array>
    <string>sudo</string>
    <string>/Library/Frameworks/Mono.framework/Versions/Current/bin/mono-service2</string>
    <string>-d:/Users/nvadmin/MacCustomizationWorker</string>
    <string>/Users/nvadmin/MacCustomizationWorker/Worker.Container.exe</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceDescription</key>
<string>Worker Container</string>
<key>WorkingDirectory</key>
<string>/Users/nvadmin/MacCustomizationWorker</string>
</dict>
</plist>

The command to start the service does work fine when run manually

It does however not start automatically on startup. Any help? Im really stuck since this is the first time Im using a Mac.

Joe

share|improve this question

2 Answers 2

Launchd expects the programs it launches not to daemonize themselves; if they do, launchd detects it as the program exiting, and cleans up all subprocesses (i.e. kills the now-daemonized program). Depending on the daemon's start and/or keepalive conditions, it might then relaunch it, and do the whole thing over and over again. In this case, I think all you need to do is add <string>--no-daemon</string> to the ProgramArguments array.

A few more (less critical) changes I'd make: first, lose the sudo -- it's not needed (launchd runs daemons as root unless told to do otherwise), and if it were needed it wouldn't work (it needs to prompt for a password, and there's nobody available in daemon context). Second, the WorkingDirectory key and -d argument seem to do exactly the same thing; there's no point in using both. Finally, you might want to add <key>KeepAlive</key><true/>, so that if the service does crash it'll get relaunched automatically.

share|improve this answer
1  
You can also use <key>AbandonProcessGroup</key><true/> to instruct launchd not to kill the child processes if you want to allow programs to daemonize themselves. –  Courtney Faulkner Apr 19 '11 at 19:08

Launchd is freaky about permissions. If it's not owned by root:wheel, with permissions set to 600, it will most likely not do anything with that plist at startup, regardless of how you load it, or what it says inside.. You may notice a log entry about "Dubious Permissions" in such a case. If this is the problem...

sudo chown root:wheel /Library/LaunchDaemons/org.saveusfromlaunchctl.sucks.plist
sudo chmod 600 /Library/LaunchDaemons/org.saveusfromlaunchctl.sucks.plist
sudo launchctl unload -w /Library/LaunchDaemons/org.saveusfromlaunchctl.sucks.plist
sudo launchctl load -w /Library/LaunchDaemons/org.saveusfromlaunchctl.sucks.plist

Another little publicized fact about LaunchDameons is the shady smorgasbord of launchd preferences in the sanctuary of

 /var/db/launchd.db/com.apple.launchd/overrides.plist

if you've got an entry in any of those overrides.plist's with

<key>org.saveusfromlaunchctl.sucks</key>
    <dict>
        <key>Disabled</key>
        <true/>
    </dict>

That sucker ain't never gonna launch.

share|improve this answer
    
upvote for you sir. saved an un-bootable install! –  OrangeBox Jan 18 '12 at 23:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.