Skip to content
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

Handle Windows event correctly when using winsvc.rb #1155

Merged
merged 3 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

if Fluent.windows?
require 'windows/library'
require 'windows/synchronize'
require 'windows/system_info'
include Windows::Library
include Windows::Synchronize
include Windows::SystemInfo
require 'win32/ipc'
require 'win32/event'
Expand All @@ -48,6 +50,11 @@ def before_run
end
install_supervisor_signal_handlers

if config[:signame]
@signame = config[:signame]
install_windows_event_handler
end

socket_manager_path = ServerEngine::SocketManager::Server.generate_path
ServerEngine::SocketManager::Server.open(socket_manager_path)
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
Expand Down Expand Up @@ -135,6 +142,21 @@ def install_supervisor_signal_handlers
end unless Fluent.windows?
end

def install_windows_event_handler
Thread.new do
ev = Win32::Event.new(@signame)
begin
ev.reset
until WaitForSingleObject(ev.handle, 1000) == WAIT_OBJECT_0
end
kill_worker
stop(true)
ensure
ev.close
end
end
end

def supervisor_sighup_handler
kill_worker
end
Expand Down Expand Up @@ -224,6 +246,7 @@ def self.load_config(path, params = {})
pid_path = params['daemonize']
daemonize = !!params['daemonize']
main_cmd = params['main_cmd']
signame = params['signame']

se_config = {
worker_type: 'spawn',
Expand Down Expand Up @@ -253,6 +276,7 @@ def self.load_config(path, params = {})
JSON.dump(params)],
fluentd_conf: fluentd_conf,
main_cmd: main_cmd,
signame: signame,
}
if daemonize
se_config[:pid_path] = pid_path
Expand Down Expand Up @@ -490,6 +514,7 @@ def supervise
params['chgroup'] = @chgroup
params['use_v1_config'] = @use_v1_config
params['suppress_repeated_stacktrace'] = @suppress_repeated_stacktrace
params['signame'] = @signame

se = ServerEngine.create(ServerModule, WorkerModule){
Fluent::Supervisor.load_config(@config_path, params)
Expand Down
3 changes: 1 addition & 2 deletions lib/fluent/winsvc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def read_fluentdopt
require 'win32/Registry'
Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\fluentdwinsvc") do |reg|
reg.read("fluentdopt")[1]
reg.read("fluentdopt")[1] rescue ""
end
end

Expand All @@ -47,7 +47,6 @@ class FluentdService < Daemon
@pid = 0

def service_main
opt = read_fluentdopt
@pid = service_main_start
while running?
sleep 10
Expand Down