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

mac:(launchd) mange the WS App as a service #153

Merged
merged 6 commits into from
Feb 5, 2020

Conversation

afiune
Copy link

@afiune afiune commented Feb 3, 2020

Description

This change is adding a new scripts/ folder with a shell script
called chef_workstation_app_launcher that will control the app
launcher behavior for MacOS systems.

Load the app as a service:

$ chef_workstation_app_launcher load

Remove the app as a service:

$ chef_workstation_app_launcher remove

Show launchd information about the app as a service:

$ chef_workstation_app_launcher show
{
	"LimitLoadToSessionType" = "Aqua";
	"MachServices" = {
		"sh.chef.chef-workstation.MachPortRendezvousServer.6956" = mach-port-object;
	};
	"Label" = "chef.workstation.app";
	"TimeOut" = 30;
	"OnDemand" = true;
	"LastExitStatus" = 0;
	"PID" = 6956;
	"Program" = "/Applications/Chef Workstation App.app/Contents/MacOS/Chef Workstation App";
	"ProgramArguments" = (
		"/Applications/Chef Workstation App.app/Contents/MacOS/Chef Workstation App";
	);
	"PerJobMachServices" = {
		"com.apple.tsm.portname" = mach-port-object;
		"com.apple.coredrag" = mach-port-object;
		"com.apple.axserver" = mach-port-object;
	};
};

Usage

$ /opt/chef-workstation/bin/chef_workstation_app_launcher --help
Usage: chef_workstation_app_launcher <subcommand>

Controls the Chef Workstation App launcher behavior for MacOS systems.

Subcommands:
    show      Show launchd information about the Chef Workstation App service.
    load      Bootstraps the Chef Workstation App service.
    remove    Removes the Chef Workstation App service.

Signed-off-by: Salim Afiune afiune@chef.io

Related Issue

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

Salim Afiune added 2 commits February 3, 2020 15:13
This change is adding a new `scripts/` folder with a shell script
called `chef_workstation_app_launcher` that will control the app
launcher behavior for MacOS systems.

Load the app as a service:
```
$ chef_workstation_app_launcher load
```

Remove the app as a service:
```
$ chef_workstation_app_launcher remove
```

Signed-off-by: Salim Afiune <afiune@chef.io>
Show launchd information about the Chef Workstation App service.

Signed-off-by: Salim Afiune <afiune@chef.io>
@afiune afiune added Aspect: Stability Consistent results. Platform: macOS Type: Enhancement Adds new functionality. Triage: Feature Request Indicates an issue requesting new functionality. labels Feb 3, 2020
@afiune afiune self-assigned this Feb 3, 2020
@afiune afiune requested review from a team February 3, 2020 22:25
afiune pushed a commit to chef/chef-workstation that referenced this pull request Feb 3, 2020
This change has a dependency to chef/chef-workstation-app#153

Signed-off-by: Salim Afiune <afiune@chef.io>
afiune pushed a commit to chef/chef-workstation that referenced this pull request Feb 3, 2020
This change has a dependency to chef/chef-workstation-app#153

Signed-off-by: Salim Afiune <afiune@chef.io>
@afiune
Copy link
Author

afiune commented Feb 4, 2020

Launched an ad hoc build but for some reason the MacOS packages are not being
tagged correctly so I can't find the correct package, I am trying to build locally now.

Salim Afiune added 3 commits February 4, 2020 14:17
Signed-off-by: Salim Afiune <afiune@chef.io>
Signed-off-by: Salim Afiune <afiune@chef.io>
@afiune
Copy link
Author

afiune commented Feb 4, 2020

With the commit chef/chef-workstation@1637621 now the ad hoc build is passing

cc/ @jonsmorrow

tenor-138634906

Copy link
Contributor

@tyler-ball tyler-ball left a comment

Choose a reason for hiding this comment

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

Code looks clear to me. Did you get the launcher script based on anything existing?

@afiune
Copy link
Author

afiune commented Feb 4, 2020

@tyler-ball nope. I just made my own 😂 I did read the man page for the launchd daemon agent:

https://www.manpagez.com/man/5/launchd.plist/

@tyler-ball
Copy link
Contributor

Even more impressive!

@afiune
Copy link
Author

afiune commented Feb 4, 2020

@tyler-ball I wanna disclose that, I had already thought about this launcher script
since I needed to control the "start at boot" via a checkbox inside the Preferences
Dialog (PR #125). Now, with this script, we will be able in the future to control such
behavior by adding an extra sub-command called (maybe) disable.

Idea:

$ /opt/chef-workstation/bin/chef_workstation_app_launcher --help
Usage: chef_workstation_app_launcher <subcommand>

Controls the Chef Workstation App launcher behavior for MacOS systems.

Subcommands:
    show      Show launchd information about the Chef Workstation App service.
    load      Bootstraps the Chef Workstation App service.
    remove    Removes the Chef Workstation App service.
    disable   Disable the Chef Workstation App to start at boot.

cat <<DOC
Usage: ${PROGNAME} <subcommand>

Controls the ${PRODUCTNAME} launcher behavior for MacOS systems.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Controls the ${PRODUCTNAME} launcher behavior for MacOS systems.
Controls the ${PRODUCTNAME} launcher behavior for macOS systems.

main()
{
if ! is_darwin; then
error_exit "Launcher is only available for MacOS systems"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
error_exit "Launcher is only available for MacOS systems"
error_exit "Launcher is only available for macOS systems"

Copy link
Contributor

@jonsmorrow jonsmorrow left a comment

Choose a reason for hiding this comment

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

LGTM. My only comment is that it might make sense to make this generic so the api is chef_workstation_launcher load app this way it could potentially be used for future services too. Also that's a change we could make later so long as this is never a public api.

@afiune
Copy link
Author

afiune commented Feb 5, 2020

@jonsmorrow I will change it. My only concern is that users might get confused by the name today since this is very specific for the WS App. Hopefully not 🤞

@jonsmorrow
Copy link
Contributor

jonsmorrow commented Feb 5, 2020

@afiune we could add to the help output a list of supported options or have it launch all without an argument

@afiune
Copy link
Author

afiune commented Feb 5, 2020

@jonsmorrow it already does that 💯

Signed-off-by: Salim Afiune <afiune@chef.io>
@jonsmorrow jonsmorrow merged commit c2ff7b3 into master Feb 5, 2020
@chef-expeditor chef-expeditor bot deleted the afiune/chef_workstation_app_launcher branch February 5, 2020 23:36
afiune pushed a commit to chef/chef-workstation that referenced this pull request Feb 5, 2020
This change has a dependency to chef/chef-workstation-app#153

Signed-off-by: Salim Afiune <afiune@chef.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Aspect: Stability Consistent results. Platform: macOS Triage: Feature Request Indicates an issue requesting new functionality. Type: Enhancement Adds new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants