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