Merge pull request #24342 from xucian/systemd-restart-on-failed-exit

Restart systemd services on unsuccessful exit
This commit is contained in:
Mike McQuaid authored and GitHub committed 2026-10-24 06:55:00 +00:00
commit e936c31af5
2 files changed
+27 -2

No files matched your search

+2 -2
View File
@@ -685,8 +685,8 @@ module Homebrew
if @keep_alive[:always].present? || @keep_alive[:crashed].present?
# Use on-failure instead of always to allow manual stops via systemctl
options << "Restart=on-failure"
elsif @keep_alive[:successful_exit].present?
options << "Restart=on-success"
elsif @keep_alive.key?(:successful_exit)
options << "Restart=#{@keep_alive[:successful_exit] ? "on-success" : "on-failure"}"
end
end
options << "RestartSec=#{restart_delay}" if @restart_delay.present?
+25
View File
@@ -1186,6 +1186,31 @@ RSpec.describe Homebrew::Service do
expect(unit).to eq(unit_expect)
end
it "returns valid unit with keep_alive successful_exit false" do
f = stub_formula do
T.bind(self, T.class_of(Formula))
service do
run opt_bin/"beanstalkd"
keep_alive successful_exit: false
end
end
unit = f.service.to_systemd_unit
unit_expect = <<~SYSTEMD
[Unit]
Description=Homebrew generated unit for formula_name
[Install]
WantedBy=default.target
[Service]
Type=simple
ExecStart="#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd"
Restart=on-failure
SYSTEMD
expect(unit).to eq(unit_expect)
end
it "returns valid unit with stop_timeout" do
f = stub_formula do
T.bind(self, T.class_of(Formula))