Skip to content

Backport(v1.16): winsvc: Stop the service when the supervisor is dead (#4909) #4942

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

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/fluent/winsvc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def service_main_start(service_name)
end

class FluentdService < Daemon
ERROR_WAIT_NO_CHILDREN = 128

@pid = 0
@service_name = ''

Expand All @@ -57,18 +59,21 @@ def initialize(service_name)

def service_main
@pid = service_main_start(@service_name)
while running?
sleep 10
begin
loop do
sleep 5
break unless running?
raise Errno::ECHILD unless Process.waitpid2(@pid, Process::WNOHANG)
end
rescue Errno::ECHILD
@pid = 0
SetEvent(@@hStopEvent)
SetTheServiceStatus.call(SERVICE_STOPPED, ERROR_WAIT_NO_CHILDREN, 0, 0)
end
end

def service_stop
if @pid <= 0
set_event(@service_name)
return
end

wait_supervisor_finished
wait_supervisor_finished if @pid > 0
end

def service_paramchange
Expand Down