-
Notifications
You must be signed in to change notification settings - Fork 1.4k
winsvc: Stop the service when the supervisor is dead #4909
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
Conversation
7c6e0ab to
a254703
Compare
|
Unfortunately it's hard to write tests for windows service. |
Watson1978
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
a254703 to
82dba11
Compare
|
Thanks! I share my check scripts for now.
require "win32/daemon"
require "win32/service"
class TestService < Win32::Daemon
File.open("/test/log/test_service.log", 'a') { |f| f.puts "#{Time.now.inspect}, TestService init" }
def service_main
count = 0
while running?
File.open("/test/log/test_service.log", 'a') { |f| f.puts "#{Time.now.inspect}, TestService mainloop" }
sleep 2
begin
count += 1
raise Errno::ECHILD if count >= 2
rescue Errno::ECHILD
File.open("/test/log/test_service.log", 'a') { |f| f.puts "#{Time.now.inspect}, TestService trigger stop" }
SetTheServiceStatus.call(SERVICE_STOPPED, Errno::ECHILD::Errno, 0, 0)
# Service.stop("testservice")
# SetEvent(@@hStopEvent)
break
end
end
end
def service_stop
File.open("/test/log/command_receiver_thread.log", 'a') { |f| f.puts "#{Time.now.inspect}, TestService service_stop called" }
end
end
TestService.new.mainloop
require "win32/service"
# Specify ruby bin path
ruby_path = "C:\\Ruby32-x64\\bin\\ruby.exe"
Win32::Service.create(
service_name: "testservice",
binary_path_name: "\"#{ruby_path}\" C:\\test\\run.rb",
display_name: "testservice",
)
echo "Clear logs"
rm /test/log/*
echo "Start the service"
Start-Service testservice
echo "Waiting for a while ..."
sleep 6
echo "Check service status:"
Get-Service testservice
echo "`nCheck Ruby process:"
ps -Name ruby
echo "`nLog:"
cat /test/log/* | sort
echo "`nLatest System EventLogs:"
Get-EventLog System -newest 3 | fl * |
daipom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashie
Thanks!
This seems to be the right way to stop the service process!
I have commented on some minor points.
Please check them.
82dba11 to
2ef6a86
Compare
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. Signed-off-by: Takuro Ashie <[email protected]>
2ef6a86 to
3b9c442
Compare
daipom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM!
**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]> Signed-off-by: Kentaro Hayashi <[email protected]>
**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]> Signed-off-by: Kentaro Hayashi <[email protected]>
…#4909) (#4942) **Which issue(s) this PR fixes**: Backport #4909 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]> Signed-off-by: Kentaro Hayashi <[email protected]> Co-authored-by: Takuro Ashie <[email protected]>
After 53bcd3c (fluent#4909), the service accidentally stops after starting, without stopping the supervisor and workers. Signed-off-by: Daijiro Fukuda <[email protected]>
|
I'm sorry. I have made a PR to fix this bug and adding tests: |
After 53bcd3c (fluent#4909), the service accidentally stops after starting, without stopping the supervisor and workers. Signed-off-by: Daijiro Fukuda <[email protected]>
After 53bcd3c (fluent#4909), the service accidentally stops after starting, without stopping the supervisor and workers. Signed-off-by: Daijiro Fukuda <[email protected]>
After 53bcd3c (fluent#4909), the service accidentally stops after starting, without stopping the supervisor and workers. Signed-off-by: Daijiro Fukuda <[email protected]>
After 53bcd3c (fluent#4909), the service accidentally stops after starting, without stopping the supervisor and workers. Signed-off-by: Daijiro Fukuda <[email protected]>
After 53bcd3c (fluent#4909), the service accidentally stops after starting, without stopping the supervisor and workers. Signed-off-by: Daijiro Fukuda <[email protected]>
After 53bcd3c (fluent#4909), the service accidentally stops after starting, without stopping the supervisor and workers. Signed-off-by: Daijiro Fukuda <[email protected]> Co-authored-by: Takuro Ashie <[email protected]>
After 53bcd3c (fluent#4909), the service accidentally stops after starting, without stopping the supervisor and workers. Signed-off-by: Daijiro Fukuda <[email protected]> Co-authored-by: Takuro Ashie <[email protected]> Co-authored-by: Kentaro Hayashi <[email protected]>
**Which issue(s) this PR fixes**: This fixes a bug of #4909. **What this PR does / why we need it**: After 53bcd3c (#4909), the service accidentally stops after starting, without stopping the supervisor and workers. **Docs Changes**: Not needed. **Release Note**: The same as the title. Signed-off-by: Daijiro Fukuda <[email protected]> Co-authored-by: Takuro Ashie <[email protected]> Co-authored-by: Kentaro Hayashi <[email protected]>
**Which issue(s) this PR fixes**: This fixes a bug of #4909. **What this PR does / why we need it**: After 53bcd3c (#4909), the service accidentally stops after starting, without stopping the supervisor and workers. **Docs Changes**: Not needed. **Release Note**: The same as the title. Signed-off-by: Daijiro Fukuda <[email protected]> Co-authored-by: Takuro Ashie <[email protected]> Co-authored-by: Kentaro Hayashi <[email protected]> Signed-off-by: Daijiro Fukuda <[email protected]>
**Which issue(s) this PR fixes**: This fixes a bug of #4909. **What this PR does / why we need it**: After 53bcd3c (#4909), the service accidentally stops after starting, without stopping the supervisor and workers. **Docs Changes**: Not needed. **Release Note**: The same as the title. Signed-off-by: Daijiro Fukuda <[email protected]> Co-authored-by: Takuro Ashie <[email protected]> Co-authored-by: Kentaro Hayashi <[email protected]> Signed-off-by: Daijiro Fukuda <[email protected]>
**Which issue(s) this PR fixes**: This fixes a bug of #4909. **What this PR does / why we need it**: After 53bcd3c (#4909), the service accidentally stops after starting, without stopping the supervisor and workers. **Docs Changes**: Not needed. **Release Note**: The same as the title. Signed-off-by: Daijiro Fukuda <[email protected]> Co-authored-by: Takuro Ashie <[email protected]> Co-authored-by: Kentaro Hayashi <[email protected]> Signed-off-by: Daijiro Fukuda <[email protected]>
…er starting (#4954) (#4955) **Which issue(s) this PR fixes**: Backport #4954. **What this PR does / why we need it**: After 53bcd3c (#4909), the service accidentally stops after starting, without stopping the supervisor and workers. **Docs Changes**: Not needed. **Release Note**: The same as the title. Signed-off-by: Daijiro Fukuda <[email protected]> Co-authored-by: Takuro Ashie <[email protected]> Co-authored-by: Kentaro Hayashi <[email protected]>
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.