Merge pull request #11298 from SMillerDev/feature/service/plist_options

services: replace plist_options :manual with service command
This commit is contained in:
Sean Molenaar 2021-05-04 15:07:28 +02:00 committed by GitHub
commit 1de2b234b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 33 deletions

View File

@ -152,13 +152,19 @@ class Caveats
end end
def plist_caveats def plist_caveats
return unless f.plist_manual return if !f.plist_manual && !f.service?
command = if f.service?
f.service.command.join(" ")
else
f.plist_manual
end
# Default to brew services not being supported. macOS overrides this behavior. # Default to brew services not being supported. macOS overrides this behavior.
<<~EOS <<~EOS
#{Formatter.warning("Warning:")} #{f.name} provides a launchd plist which can only be used on macOS! #{Formatter.warning("Warning:")} #{f.name} provides a launchd plist which can only be used on macOS!
You can manually execute the service instead with: You can manually execute the service instead with:
#{f.plist_manual} #{command}
EOS EOS
end end

View File

@ -6,44 +6,50 @@ class Caveats
def plist_caveats def plist_caveats
s = [] s = []
if f.plist || keg&.plist_installed? return if !f.plist && !f.service? && !keg&.plist_installed?
plist_domain = f.plist_path.basename(".plist")
# we readlink because this path probably doesn't exist since caveats plist_domain = f.plist_path.basename(".plist")
# occurs before the link step of installation
# Yosemite security measures mildly tighter rules: # we readlink because this path probably doesn't exist since caveats
# https://github.com/Homebrew/legacy-homebrew/issues/33815 # occurs before the link step of installation
if !plist_path.file? || !plist_path.symlink? # Yosemite security measures mildly tighter rules:
if f.plist_startup # https://github.com/Homebrew/legacy-homebrew/issues/33815
s << "To have launchd start #{f.full_name} now and restart at startup:" if f.plist && (!plist_path.file? || !plist_path.symlink?)
s << " sudo brew services start #{f.full_name}" if f.plist_startup
else s << "To have launchd start #{f.full_name} now and restart at startup:"
s << "To have launchd start #{f.full_name} now and restart at login:" s << " sudo brew services start #{f.full_name}"
s << " brew services start #{f.full_name}"
end
# For startup plists, we cannot tell whether it's running on launchd,
# as it requires for `sudo launchctl list` to get real result.
elsif f.plist_startup
s << "To restart #{f.full_name} after an upgrade:"
s << " sudo brew services restart #{f.full_name}"
elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null"
s << "To restart #{f.full_name} after an upgrade:"
s << " brew services restart #{f.full_name}"
else else
s << "To start #{f.full_name}:" s << "To have launchd start #{f.full_name} now and restart at login:"
s << " brew services start #{f.full_name}" s << " brew services start #{f.full_name}"
end end
# For startup plists, we cannot tell whether it's running on launchd,
# as it requires for `sudo launchctl list` to get real result.
elsif f.plist_startup
s << "To restart #{f.full_name} after an upgrade:"
s << " sudo brew services restart #{f.full_name}"
elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null"
s << "To restart #{f.full_name} after an upgrade:"
s << " brew services restart #{f.full_name}"
else
s << "To start #{f.full_name}:"
s << " brew services start #{f.full_name}"
end
if f.plist_manual if f.plist_manual || f.service?
s << "Or, if you don't want/need a background service you can just run:" command = if f.service?
s << " #{f.plist_manual}" f.service.command.join(" ")
else
f.plist_manual
end end
# pbpaste is the system clipboard tool on macOS and fails with `tmux` by default s << "Or, if you don't want/need a background service you can just run:"
# check if this is being run under `tmux` to avoid failing s << " #{command}"
if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") end
s << "" << "WARNING: brew services will fail when run under tmux."
end # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default
# check if this is being run under `tmux` to avoid failing
if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste")
s << "" << "WARNING: brew services will fail when run under tmux."
end end
"#{s.join("\n")}\n" unless s.empty? "#{s.join("\n")}\n" unless s.empty?
end end

View File

@ -114,6 +114,20 @@ describe Caveats do
expect(caveats).to include(f.plist_manual) expect(caveats).to include(f.plist_manual)
end end
it "gives information about service" do
f = formula do
url "foo-1.0"
service do
run [bin/"php", "test"]
end
end
caveats = described_class.new(f).caveats
expect(f.service?).to eq(true)
expect(caveats).to include("#{f.bin}/php test")
expect(caveats).to include("background service")
end
it "warns about brew failing under tmux" do it "warns about brew failing under tmux" do
f = formula do f = formula do
url "foo-1.0" url "foo-1.0"