diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index f27ff1e318..6a0d76ee22 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -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' @@ -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 @@ -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 @@ -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', @@ -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 @@ -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) diff --git a/lib/fluent/winsvc.rb b/lib/fluent/winsvc.rb index 674f6b57a9..fca7c99d78 100644 --- a/lib/fluent/winsvc.rb +++ b/lib/fluent/winsvc.rb @@ -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 @@ -47,7 +47,6 @@ class FluentdService < Daemon @pid = 0 def service_main - opt = read_fluentdopt @pid = service_main_start while running? sleep 10