Skip to content

Instantly share code, notes, and snippets.

@holysugar
Forked from shun0102/deploy.rb
Last active December 14, 2015 20:08
Show Gist options
  • Save holysugar/5141672 to your computer and use it in GitHub Desktop.
Save holysugar/5141672 to your computer and use it in GitHub Desktop.
require 'securerandom'
namespace :td do
task :start, :roles => :fluentd do
run "#{try_sudo} /etc/init.d/td-agent start"
end
task :stop, :roles => :fluentd do
run "#{try_sudo} /etc/init.d/td-agent stop"
end
task :restart, :roles => :fluentd do
run "#{try_sudo} /etc/init.d/td-agent restart"
end
task :reload, :roles => :fluentd do
run "#{try_sudo} /etc/init.d/td-agent reload"
end
task :flush, :roles => :fluentd do
run "#{try_sudo} pkill -USR1 td-agent"
end
task :setup, :roles => :fluentd do
logdir = fetch(:logdir, "/var/log/td-agent")
run "#{try_sudo} mkdir -p #{logdir}"
run "#{try_sudo} chown td-agent:td-agent #{logdir}"
end
task :deploy, :roles => :fluentd do
td_config = fetch(:td_config, "/etc/td-agent/td-agent.conf")
tmp = "/tmp/td-agent-#{SecureRandom.uuid}.conf"
upload(configfile, tmp)
run "#{try_sudo} mv #{tmp} #{td_config}"
restart
end
task :gems, :roles => :fluentd do
require 'securerandom'
tmpdir = "/tmp/td-agent-#{SecureRandom.uuid}"
run "mkdir -p #{tmpdir}"
upload(gemfile, "#{tmpdir}/Gemfile")
bundle = fetch(:bundle_bin, "/usr/lib64/fluent/ruby/bin/bundle")
option = fetch(:bundle_flags, "--quiet --without test development")
run "cd #{tmpdir}; #{try_sudo} #{bundle} install #{option}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment