4

I am trying to use some init.d script under OS X and I while some are just working properly, I discovered quite a few that to rely on /sbin/start-stop-daemon and I am looking for a port of it for OS X.

Any ideas?

Note, I know that OS X does not have support for init.d but there is nothing stoping you from using it to start/stop some services. It is much easier to install things like postgres, nginx using brew and control them using the usual service name start|stop|restart.

  • I too want this. I don't want to use a separate tool because I want to play with it locally on my Macbook for learning before I make changes to a Linux server running my apps which uses start-stop-daemon. – Sridhar-Sarnobat Nov 30 '17 at 1:26
2

You need to look at launchd which uses *.plist setup files in:

/Library/LaunchAgents/, /Library/LaunchDaemons/ and ~/Library/LaunchAgents/

Under /System/Library/LaunchAgents/ and /System/Library/LaunchDaemons/ are the ones provided by Mac OS X.

When you e.g. install postgresql form Macports, there will also be installed an org.macports.postgresql93-server.plist file under /Library/LaunchDaemons/ (it is a link to a .plist file which is installed under /opt/local/etc/LaunchDaemons/org.macports.postgresql93-server), but the daemon isn't enabled at install.

The content of this .plist file is (the key <key>Disabled</key><true/> need to be set to false, if you need to enable the daemon):

<?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>org.macports.postgresql93-server</string>
<key>ProgramArguments</key>
<array>
    <string>/opt/local/bin/daemondo</string>
    <string>--label=postgresql93-server</string>
    <string>--start-cmd</string>
    <string>/opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper</string>
    <string>start</string>
    <string>;</string>
    <string>--stop-cmd</string>
    <string>/opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper</string>
    <string>stop</string>
    <string>;</string>
    <string>--restart-cmd</string>
    <string>/opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper</string>
    <string>restart</string>
    <string>;</string>
    <string>--pid=none</string>
</array>
<key>Debug</key><false/>
<key>Disabled</key><true/>
<key>KeepAlive</key><true/>
</dict>
</plist>
  • Man that's a lot of work. Plain old Unix design is so much more compact. And it's not just Mac OS X that are burdening the user here, systemd and upstart have gone in this direction too. – Sridhar-Sarnobat Dec 12 '17 at 1:28
2

Rene Larsen's answer holds the secret but it was not called out. What you want to do is to install MacPorts, which provides the daemondo program (installed to /opt/local/bin/daemondo on my system).

From the help screen: "daemondo is a wrapper program that runs daemons." It appears to provide arguments and functionality similar to start-stop-daemon.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .