macos sudo install command creates invalid LaunchDaemon
Summary
On macOS, running sudo gitlab-runner install --user some-user ...
creates a launchd
daemon (which is good), that doesn't actually run (which is bad).
Steps to reproduce
brew install gitlab-runner --without-docker
sudo gitlab-runner install --user some-user
sudo gitlab-runner start
Actual behavior
The created daemon fails to start: sudo gitlab-runner status
will print that the service is not running, most of the time, but every so often will print that it is. This is because launchd
is trying to start the service every 10 seconds, tail /var/log/system.log
shows repeated:
May 18 16:38:41 mac-build com.apple.xpc.launchd[1] (gitlab-runner[96477]): Service exited with abnormal code: 1
May 18 16:38:41 mac-build com.apple.xpc.launchd[1] (gitlab-runner): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.
From observation, gitlab-runner install
creates a /Library/LaunchDaemons/gitlab-runner.plist
with:
<?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>gitlab-runner</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/Cellar/gitlab-runner/10.7.1/bin/gitlab-runner</string>
<string>run</string>
<string>--working-directory</string>
<string>/GitlabRunner</string>
<string>--config</string>
<string>/etc/gitlab-runner/config.toml</string>
<string>--service</string>
<string>gitlab-runner</string>
<string>--syslog</string>
<string>--user</string>
<string>some-user</string>
</array>
<key>SessionCreate</key><false/>
<key>KeepAlive</key><true/>
<key>RunAtLoad</key><true/>
<key>Disabled</key><false/>
</dict>
</plist>
This doesn't follow apple's recommendations in their launch daemon docs, so I started digging...
Turns out the issue is gitlab-runner run
was failing on startup due to $HOME
being undefined (reasonably), which was due to UserName
not being defined in the config.
Expected behavior
I ended up with the following config:
<?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.gitlab.gitlab-runner</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/Cellar/gitlab-runner/10.7.1/bin/gitlab-runner</string>
<string>run</string>
<string>--working-directory</string>
<string>/GitlabRunner</string>
<string>--config</string>
<string>/etc/gitlab-runner/config.toml</string>
<string>--service</string>
<string>gitlab-runner</string>
<string>--syslog</string>
</array>
<key>UserName</key>
<string>some-user</string>
<key>StandardOutPath</key>
<string>/var/log/gitlab-runner.log</string>
<key>StandardErrorPath</key>
<string>/var/log/gitlab-runner.log</string>
<key>SessionCreate</key><false/>
<key>KeepAlive</key><true/>
<key>RunAtLoad</key><true/>
<key>Disabled</key><false/>
</dict>
</plist>
and it seems to be working fine from there. Notable changes:
- changed the
Label
(and plist name) toorg.gitlab.gitlab-runner
to match LaunchDaemon conventions. - Replaced
--user blah
with<key>UserName</key><string>blah</string>
(ugh, plist) - Added
Standard{Out,Error}Path
values for debugging, doesn't seem to write anything otherwise.
I also did some chown
-ing on /etc/gitlab-runner/
which may or may not have been needed, and the docs claim you should be using WorkingDirectory
instead of cd
ing, but it seems to work OK.
Relevant logs and/or screenshots
Should all be above.
Environment description
Standard brew install on macOS High Sierra
Used GitLab Runner version
Version: 10.7.1
Git revision: b9bba623
Git branch: 10-7-stable
GO version: go1.10.2
Built: 2018-05-18T15:06:51+12:00
OS/Arch: darwin/amd64