Merge pull request #97 from fluent/fix_td_agent_on_mac

Fix td agent on mac
This commit is contained in:
uu59 2014-11-11 13:06:05 +09:00
commit b7bd9412a8
6 changed files with 77 additions and 23 deletions

View File

@ -2,7 +2,7 @@
module ApplicationHelper
def has_td_agent_system?
File.exist?("/etc/init.d/td-agent")
File.exist?("/etc/init.d/td-agent") || File.exist?("/opt/td-agent/embedded/bin/fluentd")
end
def fluentd_ui_logo

View File

@ -96,6 +96,14 @@ class Fluentd
ensure
io && io.close
end
def detached_command(cmd)
Bundler.with_clean_env do
pid = spawn(cmd)
Process.detach(pid)
end
sleep 1 # NOTE/FIXME: too early return will be caused incorrect status report, "sleep 1" is a adhoc hack
end
end
end
end

View File

@ -12,32 +12,15 @@ class Fluentd
}
end
def start
detached_command('/etc/init.d/td-agent start')
end
def stop
detached_command('/etc/init.d/td-agent stop')
end
def restart
# NOTE: td-agent has no reload command
# https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.init#L156
detached_command('/etc/init.d/td-agent restart')
end
def version
`/usr/sbin/td-agent --version`.strip
end
private
def detached_command(cmd)
Bundler.with_clean_env do
pid = spawn(cmd)
Process.detach(pid)
end
sleep 1 # NOTE/FIXME: too early return will be caused incorrect status report, "sleep 1" is a adhoc hack
case FluentdUI.platform
when :macosx
include Macosx
when :unix
include Unix
end
end
end

View File

@ -0,0 +1,33 @@
class Fluentd
class Agent
class TdAgent
module Macosx
def start
detached_command("launchctl load #{plist}") && pid_from_launchctl
end
def stop
detached_command("launchctl unload #{plist}") && FileUtils.rm(pid_file)
end
def restart
stop && start
end
private
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
end

View File

@ -0,0 +1,21 @@
class Fluentd
class Agent
class TdAgent
module Unix
def start
detached_command('/etc/init.d/td-agent start')
end
def stop
detached_command('/etc/init.d/td-agent stop')
end
def restart
# NOTE: td-agent has no reload command
# https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.init#L156
detached_command('/etc/init.d/td-agent restart')
end
end
end
end
end

View File

@ -29,4 +29,13 @@ module FluentdUI
def self.td_agent_ui?
ENV["FLUENTD_UI_TD_AGENT"].present?
end
def self.platform
case RbConfig::CONFIG['host_os']
when /darwin|mac os/
:macosx
else # FIXME: windows is unix? :P
:unix
end
end
end