There's a 1000 posts on this topic online and not one of them explains that you need to modify the location of the launching plist for this runner to work on sudden restarts.
Except maybe this post from symflower
Even that has it at the end so you hardly ever find it on first search unless you are looking for it and hence, this post.
This is a reference post and may or may not be helpful or detailed enough for a beginner, if you do need help with it, you can just contact me and I'll try to help you out.
Let's get done with the basic steps. These are all to be done on the remote screen / vnc app and not via ssh.
brew install --cask android-studio
gitlab-runner
brew services start gitlab-runner
Now, we get into the part where I can start things with SSH.
Now connect via SSH and copy paste the below xml to
/Library/LaunchDaemons/homebrew.mxcl.gitlab-runner.plist
and you can now restart the machine via ssh and even if the user isn't logged in via GUI, the service should still start.
Replace #user#
with the username of the CI user, preferably a non-root user.
<?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>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.gitlab-runner</string>
<key>LegacyTimers</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/opt/gitlab-runner/bin/gitlab-runner</string>
<string>--log-format=json</string>
<string>--log-level=debug</string>
<string>run</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/#user#/logs/gitlab-runner.log</string>
<key>StandardErrorPath</key>
<string>/Users/#user#/logs/gitlab-runner.log</string>
<key>UserName</key>
<string>#user#</string>
<key>WorkingDirectory</key>
<string>/Users/#user#</string>
</dict>
</plist>