Skip to content

Commit 53bcd3c

Browse files
authored
winsvc: Stop the service when the supervisor is dead (#4909)
**Which issue(s) this PR fixes**: None. **What this PR does / why we need it**: Even if the supervisor process is dead due to config error or etc, the service process will continue running unexpectedly because no one monitor it. This commit fix this issue. **Docs Changes**: Not needed. **Release Note**: Same with the title. Signed-off-by: Takuro Ashie <[email protected]>
1 parent 1f39f41 commit 53bcd3c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/fluent/winsvc.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def service_main_start(service_name)
4848
end
4949

5050
class FluentdService < Daemon
51+
ERROR_WAIT_NO_CHILDREN = 128
52+
5153
@pid = 0
5254
@service_name = ''
5355

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

5860
def service_main
5961
@pid = service_main_start(@service_name)
60-
while running?
61-
sleep 10
62+
begin
63+
loop do
64+
sleep 5
65+
break unless running?
66+
raise Errno::ECHILD unless Process.waitpid2(@pid, Process::WNOHANG)
67+
end
68+
rescue Errno::ECHILD
69+
@pid = 0
70+
SetEvent(@@hStopEvent)
71+
SetTheServiceStatus.call(SERVICE_STOPPED, ERROR_WAIT_NO_CHILDREN, 0, 0)
6272
end
6373
end
6474

6575
def service_stop
66-
if @pid <= 0
67-
set_event(@service_name)
68-
return
69-
end
70-
71-
wait_supervisor_finished
76+
wait_supervisor_finished if @pid > 0
7277
end
7378

7479
def service_paramchange

0 commit comments

Comments
 (0)