From c7233a565e1a03230cb8dda0005f78d1e4f5684b Mon Sep 17 00:00:00 2001 From: uu59 Date: Tue, 11 Nov 2014 12:46:08 +0900 Subject: [PATCH] Fix to create pidfile on Mac --- app/models/fluentd/agent/td_agent/macosx.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/fluentd/agent/td_agent/macosx.rb b/app/models/fluentd/agent/td_agent/macosx.rb index 27fc785..84925d2 100644 --- a/app/models/fluentd/agent/td_agent/macosx.rb +++ b/app/models/fluentd/agent/td_agent/macosx.rb @@ -4,11 +4,11 @@ class Fluentd module Macosx def start - detached_command("launchctl load #{plist}") + detached_command("launchctl load #{plist}") && pid_from_launchctl end def stop - detached_command("launchctl unload #{plist}") + detached_command("launchctl unload #{plist}") && FileUtils.rm(pid_file) end def restart @@ -20,6 +20,13 @@ class Fluentd def plist '/Library/LaunchDaemons/td-agent.plist' end + + def pid_from_launchctl + # NOTE: launchctl doesn't make pidfile, so detect pid and store it to pidfile manually + pid = `launchctl list | grep td-agent | cut -f1`.strip + return if pid == "" + File.open(pid_file, "w"){|f| f.write pid } + end end end end