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
Convert to using launchctl bootstrap instead of deprecated launchctl load -w #112
Changes from 5 commits
66ddb80
72032ae
13e63c1
07a2237
ef898bb
0a5511c
187e3f6
e4637ba
f61a707
cd4fc93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#: * `services` | ||
#: Easily start and stop formulae via launchctl | ||
#: * `services` [`-v`|`--verbose`] [list | run | start | stop | restart | cleanup] [...] | ||
#: Easily start and stop formulae via launchctl. | ||
#: With `-v` or `--verbose`, print more detail. | ||
#: | ||
#: Integrates Homebrew formulae with OS X's `launchctl` manager. Services can be | ||
#: added to either `/Library/LaunchDaemons` or `~/Library/LaunchAgents`. | ||
|
@@ -236,6 +237,33 @@ def restart(target) | |
end | ||
end | ||
|
||
# "load" a plist | ||
def launchctl_load(plist, _function, service) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skip There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it looks like it probably wants to be called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was the intention, but I was concerned that changing the message from "started" run "ran" in the (On the other hand, maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes.
That was to preserve backwards compatibility of commands. |
||
if root? | ||
domain_target = "system" | ||
else | ||
domain_target = "gui/#{Process.uid}" | ||
end | ||
|
||
if MacOS.version < :yosemite | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pedantry but make this the |
||
# This syntax was deprecated in Yosemite | ||
safe_system launchctl, "load", "-w", plist | ||
else | ||
# New syntax has improved errr-handling. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can remove this comment. |
||
safe_system launchctl, "enable", "#{domain_target}/#{service.label}" | ||
if $?.to_i.nonzero? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
odie("Failed to enable `#{service.name}`") | ||
end | ||
|
||
safe_system launchctl, "bootstrap", domain_target, plist | ||
end | ||
if $?.to_i.nonzero? | ||
odie("Failed to start `#{service.name}`") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
else | ||
ohai("Successfully started `#{service.name}` (label: #{service.label})") | ||
end | ||
end | ||
|
||
# Run a service. | ||
def run(target) | ||
if target.is_a?(Service) && target.loaded? | ||
|
@@ -244,13 +272,7 @@ def run(target) | |
end | ||
|
||
Array(target).each do |service| | ||
safe_system launchctl, "load", "-w", service.plist | ||
|
||
if $?.to_i.nonzero? | ||
odie("Failed to start `#{service.name}`") | ||
else | ||
ohai("Successfully started `#{service.name}` (label: #{service.label})") | ||
end | ||
launchctl_load(service.plist, "ran", service) | ||
end | ||
end | ||
|
||
|
@@ -295,13 +317,7 @@ def start(target, custom_plist = nil) | |
# Clear tempfile. | ||
temp.close | ||
|
||
safe_system launchctl, "load", "-w", service.dest.to_s | ||
|
||
if $?.to_i.nonzero? | ||
odie("Failed to start `#{service.name}`") | ||
else | ||
ohai("Successfully started `#{service.name}` (label: #{service.label})") | ||
end | ||
launchctl_load(service.dest.to_s, "started", service) | ||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can skip this comment, pretty self-explanatory.