Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require GUI to run as service #2465

Closed

Conversation

frederickjansen
Copy link

There are a couple of changes in this pull request:

  1. Don't require GUI to run as service
  2. Use updated launchctl syntax
  3. Don't require running service to uninstall
  1. This is achieved by setting the session to be Background instead of the default Aqua. Since Mac machines are supported on AWS and it's cumbersome to require the use of a GUI, running this as a background service makes sense.
  2. Starting with macOS 10.10 there's a new syntax for launchctl. Specifically I make use of launchctl bootstrap user/UID and launchctl bootout user/UID. Specifying the user context rather than gui makes sure this service runs in the background as well.
  3. Somewhat unrelated perhaps but in testing I noticed that it was impossible to uninstall the service after stopping it. stop() would trigger the failed state if the service was already stopped, halting execution of the rest of the cleanup code. This would mean that if you can't start the service and want to uninstall it, you can't. I think returning true with the same error message makes more sense.

I only later realized this pull request is similar to #2449, though it doesn't use the updated launchctl syntax. In my testing I wasn't able to get that pull request to work either. The updated syntax was required to run in the background for me. This fixes #947 and #1056.

Use updated launchctl syntax
Don't require running service to uninstall
@frederickjansen frederickjansen requested a review from a team as a code owner February 27, 2023 22:09
@tcptps
Copy link

tcptps commented Mar 2, 2023

@frederickjansen thanks, for the PR (I am obvioulsy not a code owner, but I am interested in a working version for OSX) and as I mentioned in #947 (comment) this is the proper solution.
But out of curiosity would you mind to tell what issues you are having with PR 2449 ?

<string>Background</string>
<string>Aqua</string>
<string>LoginWindow</string>
<string>StandardIO</string>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to add Systemto the supported session types as well, so the service can optionally also be run as a deamon.
credit to: DrJosh9000 over at buildkite for the suggestion

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that require running ./svc.sh install as root, and then the script moving the .plist file to /Library/LaunchDaemons? There's a specific check not to run anything as root in the code so I wonder if they'll want to support that.

Copy link

@tcptps tcptps Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I am not suggesting to move to deamons but instead the idea was not to break this hotfix #1056 (comment)
But you might even want to do that intentionally because as you mentionend :

There's a specific check not to run anything as root in the code so I wonder if they'll want to support that.

@frederickjansen
Copy link
Author

@tcptps I got the same error as before. "Load failed: 5: Input/output error" It then tells you to run it as root to get more detailed information. But since it's an agent specific to a user and not a daemon, running as root just throws a different error message. That's a problem you don't get with the updated syntax.
I probably could have investigated more, but the updated syntax did work for me so I left it at that. Since GitHub runners require macOS 10.13 as a minimum anyway I think it makes sense to use the new launchctl code. That is supported on 10.10 and up.

@tuxity
Copy link
Contributor

tuxity commented May 17, 2023

Just tested the changes on a mac2.metal instance from AWS (M1 ARM) and works well!
I had the same error Load failed: 5: Input/output error

@frederickjansen
Copy link
Author

@TingluoHuang Can someone review this please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide an installer for running in a service account on self hosted Mac
5 participants