レシピです。
※setupタスクは、随時変更してください。
set_default(:conf_file) { "/etc/td-agent/td-agent.conf" }
namespace :td_agent do
desc "start td-agent"
task :start, roles: :web do
run "#{sudo} /etc/init.d/td-agent start"
end
desc "stop td-agent"
task :stop, roles: :web do
run "#{sudo} /etc/init.d/td-agent stop"
end
desc "restart td-agent"
task :restart, roles: :web do
run "#{sudo} /etc/init.d/td-agent restart"
end
desc "reload the config file"
task :reload, roles: :web do
run "#{sudo} /etc/init.d/td-agent reload"
end
desc "install td-agent by yum"
task :install, roles: :web do
run "#{sudo} yum -y install td-agent"
run "#{sudo} /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-forest"
run "#{sudo} /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-tail-ex"
end
desc "setup config files and log files"
task :setup, roles: :web do
run "#{sudo} mkdir -p /var/log/fluent"
run "#{sudo} chgrp td-agent /var/log/fluent"
run "#{sudo} chown td-agent /var/log/fluent"
run "#{sudo} chmod +x /etc/td-agent"
run "#{sudo} chmod o+w #{conf_file}"
template("td_agent.erb", conf_file)
end
namespace :log do
task :tail, roles: :web do
run "#{sudo} tail -f /var/log/td-agent/td-agent.log"
end
end
end
after "deploy:install", "td_agent:install"
after "deploy:install", "td_agent:setup"
after "deploy:cleanup", "td_agent:restart"