launchctl - Daemons Failing to Start

I am trying to adapt to launchd, but it is giving errors without the reason why.

Oct  1 06:49:26 localhost kernel[0]: mac 12.10 phy 8.1 radio 12.0 Oct  1 06:49:26 localhost kernel[0]: IPv6 packet filtering initialized, default to accept, logging disabled Oct  1 06:49:25 localhost lookupd[47]: lookupd (version 369.6) starting - Mon Oct  1 06:49:25 2007 Oct  1 06:49:26 localhost launchd: uk.org.thekellys.dnsmasq: respawning too quickly! throttling Oct  1 06:49:26 localhost launchd: uk.org.thekellys.dnsmasq: 9 more failures without living at least 60 seconds will cause job removal Oct  1 06:49:26 localhost launchd: uk.org.thekellys.dnsmasq: will restart in 10 seconds Oct  1 06:49:26 localhost dnsmasq[60]: failed to access /etc/resolv.conf: No such file or directory Oct  1 06:49:26 localhost kernel[0]: yukonosx: Ethernet address 00:17:f2:c2:32:ca Oct  1 06:49:26 localhost diskarbitrationd[44]: disk0s2    hfs      8F0C717B-05A9-32C3-A2A5-C738F6BF4D71 Hex                   / 


Now; dnsmasq does ultimately start and create the resolv.conf symlink, but why these failures? I thought maybe the network isn't up yet, but there is no way to make the network a dependency of dnsmasq under launchctl. The plist is in /Library/LaunchDaemons.

Seems to me that I can't figure out what's wrong if logging won't tell me.

I am also getting these same startup problems with my Squid daemon, but it never manages to start on startup. It is in ~/Library/LaunchAgents/, so should start on login, when the network should be up. The plist checks out fine:
$ plutil -lint Library/LaunchAgents/org.macports.Squid.plist ~/Library/LaunchAgents/org.macports.Squid.plist: OK $


It starts fine if I:
sudo launchctl load -w ~/Library/LaunchAgents/org.macports.Squid.plist


Any suggestions?

Also BTW, how can I set IPV6 to default reject? It is disabled on all interfaces, but why take a chance?

IBM A22P, Debian Linux (8 years), Etch

Posted on Oct 1, 2007 7:29 AM

Reply
8 replies

Oct 1, 2007 7:45 AM in response to Quantumstate

Maybe use SystemStarter for this. Launchd doesn't support dependencies. The idea is that launchd will launch your daemons whenever there is activity they need to handle. It is further expected that the daemons that launchd launches aren't really daemons. Here is Apple's documentation on the subject.

I haven't had a chance to actually use launchd myself, so don't take my advice as gospel. But it certainly doesn't seem like dnsmasq and squid are working with launchd. Just because Apple says something is "old and deprecated" and you should use something "new", doesn't mean you should.

I'm pretty sure that Apple has no intention of being another Linux. They want to be (and will, with 10.5) a real UNIX. But that is a different philosophy than what Linux people are used to.

Oct 1, 2007 10:42 AM in response to etresoft

I am doing my darnedest to make this work with launchd, as Startup is going away.

A big part of the problem, and the reason launchd is so inaccesible to everyone, is because there is no utility to construct launchd plists. This critical tool is simply missing from the OS. So I am using Lingon.

I have now found that the dnsmasq problem is indeed it trying to start before the network is up. And in fact after it starts, launchd keeps trying to start it, getting an error that that port is already taken. But when I turn off the plist for dnsmasq it does not start at all, so I know it is the only thing starting DNS. I just have to accept this as a problem with launchd. My daemon at least starts.

But Squid is another story. I've managed to figure out that anytime a daemon is started as a LaunchAgent, whether in my user directory or in /Library, it starts as the user logging on. This is a problem because Squid must start as the squid user. So the plist must go in /Library/LaunchDaemon, and the startup user (second tab) must be squid.

I can now do a basic start of squid with /opt/local/sbin/squid -s in the launchDaemon plist. Squid starts reliably. But before it starts, I need to test whether the cache directories are OK. This is an if-then statement, which works on the command-line, but not in the plist. Spent two full days thrashing on this so far. What a painful process.

Oct 1, 2007 11:08 AM in response to Quantumstate

Quantumstate wrote:
I am doing my darnedest to make this work with launchd, as Startup is going away.


It is not going away anytime soon.

A big part of the problem, and the reason launchd is so inaccesible to everyone, is because there is no utility to construct launchd plists. This critical tool is simply missing from the OS. So I am using Lingon.


As a configuration file for a system administrator, there is a suitable construction tool. It is called "vi".

I found some instructions on how to start squid using launchd. Are these not sufficient? I don't know about dnsmasq. Launchd has some very specific requirements. For example, are you launching it with the "-k" option as described in the MAN page?

Oct 1, 2007 12:23 PM in response to etresoft

vi is just an editor; I use nano. Many plists have binary, and you can't edit them with a text editor.

But, gee, I never thought anyone else might have set up Squid with launchd, thanks for finding that; I am used to being the pioneer, and expect to reinvent the wheel. Thing is though, his just basically starts Squid; it does not first test that the cache files are OK. I am able to start Squid with this:
<?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>Disabled</key>      <false/>      <key>Label</key>      <string>org.macports.Squid</string>      <key>OnDemand</key>      <false/>      <key>ProgramArguments</key>      <array>           <string>/opt/local/sbin/squid</string>           <string>-s</string>      </array>      <key>RunAtLoad</key>      <true/> </dict> </plist>


But the problem comes when trying to test for the presence of the cache directories. In bash scripting it would look like this:
     cd /opt/local/var/squid      if [ ! -d "/opt/local/var/squid/cache/00" ]; then           su -fm squid -c "exec /opt/local/sbin/squid -s -z"      fi      su -fm squid -c "exec /opt/local/sbin/squid -s"


I have synthesized this for launchctl as:
<?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>org.macports.Squid-new</string>      <key>ProgramArguments</key>      <array>           <string>if</string>           <string>[</string>           <string>!</string>           <string>-d</string>           <string>"/opt/local/var/squid/cache/00"</string>           <string> ];</string>           <string>then</string>           <string>/opt/local/sbin/squid</string>           <string>-s</string>           <string>-z;</string>           <string>fi</string>           <string>&amp;&amp;</string>           <string>/opt/local/sbin/squid</string>           <string>-s</string>      </array>      <key>RunAtLoad</key>      <true/>      <key>UserName</key>      <string>squid</string> </dict> </plist>


... this works on the commandline in every way, but in this plist it fails with:
Oct  1 12:20:14 Hydra-darkmatter-org launchd: org.macports.Squid-new: execve(): No such file or directory


Some minor obscure error is a showstopper.

Actually -k is not needed when used with launchd, as it takes care of startup, shutdown, etc.

Oct 1, 2007 2:13 PM in response to Quantumstate

All right, that's enough. I simply do not have the -days- it is obviously going to take to tease apart the intricacies of launchd. As there is practically zero documentation, it is clear to me that this app is still in its infancy, and it has a very delicate constitution. I am just starting Squid without checking for cache directories.

I must get back to actually making a living, rather than fiddling with arcane ideosyncracies.

Oct 1, 2007 2:28 PM in response to Quantumstate

Quantumstate wrote:
vi is just an editor; I use nano. Many plists have binary, and you can't edit them with a text editor.


There is a tool, I forget the name, that will convert a plist back to XML so you can edit it and then back to binary.

But the problem comes when trying to test for the presence of the cache directories. In bash scripting it would look like this:

cd /opt/local/var/squid
if [ ! -d "/opt/local/var/squid/cache/00" ]; then
su -fm squid -c "exec /opt/local/sbin/squid -s -z"
fi
su -fm squid -c "exec /opt/local/sbin/squid -s"


I don't think you can stuff that script code into the plist like that. You would probably have to wrap squid in a shell script and have launchd run that shell script. I don't know if that will work though.

Actually -k is not needed when used with launchd, as it takes care of startup, shutdown, etc.


I did find some launchd documentation and I bet -k would be a good option to use with launchd. But I really know nothing about launchd or squid.

Oct 1, 2007 5:12 PM in response to etresoft

Thanks etre, you may be right that a script would do this, but should it chown the process to squid or should the plist, and a hundred other unanticipated problems, which characterize my first foray into launchd. It turns out that "execve(): No such file or directory" is a nebulous bit-bucket catch-all type error which rears its ugly head in all kinds of situations, never indicating anything specific. I am just out of time to spend on this. I must get back to trying to make a living.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

launchctl - Daemons Failing to Start

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.