Skip to content

Commit

Permalink
Merge pull request #1171 from unak/win-piped-command
Browse files Browse the repository at this point in the history
Use pipe command sender mechanism of ServerEngine on Windows
  • Loading branch information
tagomoris authored Aug 30, 2016
2 parents e9ac872 + 1081c7e commit 31f34c3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def self.load_config(path, params = {})
logger_initializer.init
logger = $log

command_sender = Fluent.windows? ? "pipe" : "signal"

# ServerEngine's "daemonize" option is boolean, and path of pid file is brought by "pid_path"
pid_path = params['daemonize']
daemonize = !!params['daemonize']
Expand Down Expand Up @@ -273,6 +275,7 @@ def self.load_config(path, params = {})
WorkerModule.name,
path,
JSON.dump(params)],
command_sender: command_sender,
fluentd_conf: fluentd_conf,
main_cmd: main_cmd,
signame: signame,
Expand Down Expand Up @@ -552,6 +555,29 @@ def install_main_process_signal_handlers
trap :USR1 do
flush_buffer
end unless Fluent.windows?

if Fluent.windows?
command_pipe = STDIN.dup
STDIN.reopen(File::NULL, "rb")
command_pipe.binmode
command_pipe.sync = true

Thread.new do
loop do
cmd = command_pipe.gets.chomp
case cmd
when "GRACEFUL_STOP", "IMMEDIATE_STOP"
$log.debug "fluentd main process get #{cmd} command"
@finished = true
$log.debug "getting start to shutdown main process"
Fluent::Engine.stop
break
else
$log.warn "fluentd main process get unknown command [#{cmd}]"
end
end
end
end
end

def flush_buffer
Expand Down

0 comments on commit 31f34c3

Please sign in to comment.