How do I launch an app at boot/startup on Sierra? I'm a techie but fairly new to macOS. I am using a Mac mini running macOS Sierra as a build machine running GoCD. I want the server (go-server) and the agent (go-agent) to start on boot, but I can't find an easy explanation anywhere for how to do this. 

Things that worked on Mac OS X 10.6 don't work any more, and I don't want to have these apps start at login, because I don't want to remain logged into the console on this computer.
Service/app launch while booting is usually done with launchd and launch daemons controlled by launchctl. It depends on the app/executable and the environment if such a launch daemon is possible or not. A lot of GUI apps require a login session and the method doesn't work.

After inspecting GoCD you can either download a zip file or an "OS X/macOS app" version of the server. The server is started with a shell script in both cases: either explicitly in the zip version or implicitly with "Go Server.app/Contents/MacOS/go-server".

Go with the zip file, unzip it and move the resulting folder to /usr/local. Link the folder /usr/local/go-server-16.10.0 to /usr/local/:

ln -s /usr/local/go-server-16.10.0 /usr/local/go-server


Create a launch daemon with sudo nano /Library/LaunchDaemon/org.goserver.start.plistand the content

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;org.goserver.start&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/bin/bash&lt;/string&gt;
        &lt;string&gt;/usr/local/go-server/server.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;StandardErrorPath&lt;/key&gt;
    &lt;string&gt;/tmp/org.goserver.start.stderr&lt;/string&gt;
    &lt;key&gt;StandardOutPath&lt;/key&gt;
    &lt;string&gt;/tmp/org.goserver.start.stdout&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Change owner and permissions of the file if necessary:

sudo chown root:wheel /Library/LaunchDaemons/org.goserver.start.plist
sudo chmod 644 /Library/LaunchDaemons/org.goserver.start.plist


Modify /usr/local/go-server-16.10.0/server.sh to your needs. You should set a different log directory in line 85 or a log file will be created in the root directory. Check other variables and paths (like $JAVA_HOME, YOURKIT_PATH, $PID_FILE etc) in the shell script and modify them according to your needs/environment. Here it worked out-of-the-box - but I didn't test it thoroughly.

Then start the launch daemon with:

sudo launchctl load /Library/LaunchDaemons/org.goserver.start.plist


Check /tmp/org.goserver.start.stderr for launchd errors. If the launch daemon runs well you may remove the part:

    &lt;key&gt;StandardErrorPath&lt;/key&gt;
    &lt;string&gt;/tmp/org.goserver.start.stderr&lt;/string&gt;
    &lt;key&gt;StandardOutPath&lt;/key&gt;
    &lt;string&gt;/tmp/org.goserver.start.stdout&lt;/string&gt;


from the plist.

The method should work accordingly with the GoAgent. The start of the agent is done with agent.sh. Use a second plist with a different plist and label name of course: org.goagent.start.plist/org.goagent.start.

You probably have to add a condition in the agent's plist so that the agent is started after the server is running.



I tried the same with the "OS X" app but I failed to eliminate all errors.