diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 997c10b6e7..7ff87615b8 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -176,10 +176,11 @@ class Caveats EOS is_running_service = f.service? && quiet_system("ps aux | grep #{f.service.command&.first}") + startup = f.service&.requires_root? || f.plist_startup if is_running_service || (f.plist && quiet_system("/bin/launchctl list #{f.plist_name} &>/dev/null")) s << "To restart #{f.full_name} after an upgrade:" - s << " #{f.plist_startup ? "sudo " : ""}brew services restart #{f.full_name}" - elsif f.plist_startup + s << " #{startup ? "sudo " : ""}brew services restart #{f.full_name}" + elsif startup s << "To start #{f.full_name} now and restart at startup:" s << " sudo brew services start #{f.full_name}" else diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index 36ca7f884a..ca6de291c7 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -172,11 +172,11 @@ describe Caveats do end cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd" allow(Homebrew).to receive(:_system).and_return(true) - allow(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(false) + expect(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(false) expect(described_class.new(f).caveats).to include("login") end - it "gives information about restarting services after upgrade" do + it "gives information about plist_options restarting services after upgrade" do f = formula do url "foo-1.0" service do @@ -187,9 +187,66 @@ describe Caveats do cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd" f_obj = described_class.new(f) allow(Homebrew).to receive(:_system).and_return(true) - allow(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(true) - expect(f_obj.caveats).to include("restart #{f.full_name}") - expect(f_obj.caveats).to include("sudo") + expect(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(true) + expect(f_obj.caveats).to include(" sudo brew services restart #{f.full_name}") + end + + it "gives information about require_root restarting services after upgrade" do + f = formula do + url "foo-1.0" + service do + run [bin/"cmd"] + require_root true + end + end + cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd" + f_obj = described_class.new(f) + allow(Homebrew).to receive(:_system).and_return(true) + expect(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(true) + expect(f_obj.caveats).to include(" sudo brew services restart #{f.full_name}") + end + + it "gives information about user restarting services after upgrade" do + f = formula do + url "foo-1.0" + service do + run [bin/"cmd"] + end + end + cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd" + f_obj = described_class.new(f) + allow(Homebrew).to receive(:_system).and_return(true) + expect(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(true) + expect(f_obj.caveats).to include(" brew services restart #{f.full_name}") + end + + it "gives information about require_root starting services after upgrade" do + f = formula do + url "foo-1.0" + service do + run [bin/"cmd"] + require_root true + end + end + cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd" + f_obj = described_class.new(f) + allow(Homebrew).to receive(:_system).and_return(true) + allow(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(false) + expect(f_obj.caveats).to include(" sudo brew services start #{f.full_name}") + end + + it "gives information about user starting services after upgrade" do + f = formula do + url "foo-1.0" + service do + run [bin/"cmd"] + end + end + cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd" + f_obj = described_class.new(f) + allow(Homebrew).to receive(:_system).and_return(true) + allow(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(false) + expect(f_obj.caveats).to include(" brew services start #{f.full_name}") end it "gives information about service manual command" do @@ -203,7 +260,7 @@ describe Caveats do cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd" caveats = described_class.new(f).caveats - expect(caveats).to include("background service") + expect(caveats).to include("if you don't want/need a background service") expect(caveats).to include("VAR=\"foo\" #{cmd} start") end end