personal_deity/lib/personal_diety/capistrano.rb

107 lines
3.0 KiB
Ruby
Raw Normal View History

2012-07-03 21:54:07 +00:00
require 'capistrano'
2012-07-04 02:33:16 +00:00
require 'personal_deity'
2012-07-03 21:54:07 +00:00
require 'erb'
Capistrano::Configuration.instance(true).load do
def _cset(name, *args, &block)
set(name, *args, &block) if !exists?(name)
end
_cset(:god_port) { 23132 }
_cset(:god_log_level) { :warn }
2012-07-04 02:33:16 +00:00
_cset(:personal_deity_local_app_config) { 'config/god.conf' }
2012-07-03 21:54:07 +00:00
2012-07-04 02:33:16 +00:00
def personal_deity_target
@personal_deity_target ||= Pathname(capture("echo $HOME/personal_deity").strip)
2012-07-03 21:54:07 +00:00
end
2012-07-04 02:33:16 +00:00
def personal_deity_config_dir
Pathname("#{personal_deity_target}/god.d")
2012-07-03 21:54:07 +00:00
end
2012-07-04 02:33:16 +00:00
def personal_deity_command
personal_deity_target.join("god")
2012-07-03 21:54:07 +00:00
end
2012-07-04 02:33:16 +00:00
def generate_personal_deity_command(*args)
"cd #{personal_deity_target} && #{personal_deity_command} #{args.join(' ')}"
2012-07-03 21:54:07 +00:00
end
2012-07-04 02:33:16 +00:00
def run_personal_deity_command(*args)
run generate_personal_deity_command(*args) + "; true"
2012-07-03 21:54:07 +00:00
end
2012-07-04 02:33:16 +00:00
namespace :personal_deity do
2012-07-03 21:54:07 +00:00
desc "Install the God config for this app"
task :install do
2012-07-04 02:33:16 +00:00
template = ERB.new(File.read(personal_deity_local_app_config)).result(binding)
upload_target = personal_deity_config_dir.join("#{application}.god")
2012-07-03 21:54:07 +00:00
top.upload StringIO.new(template), upload_target.to_s
2012-07-04 02:33:16 +00:00
run_personal_deity_command :load, upload_target.to_s
2012-07-03 21:54:07 +00:00
end
namespace :service do
desc "Set up a copy of God to run for this user"
task :setup do
2012-07-04 02:33:16 +00:00
run "mkdir -p #{personal_deity_config_dir.to_s}"
2012-07-03 21:54:07 +00:00
2012-07-04 02:33:16 +00:00
config_path = "#{personal_deity_target}/god.conf"
2012-07-03 21:54:07 +00:00
2012-07-04 02:33:16 +00:00
Personaldeity.skel.capistrano.find do |file|
2012-07-03 21:54:07 +00:00
if file.file?
template = ERB.new(file.read).result(binding)
2012-07-04 02:33:16 +00:00
upload_target = personal_deity_target.join(file.relative_path_from(Personaldeity.skel.capistrano))
2012-07-03 21:54:07 +00:00
top.upload StringIO.new(template), upload_target.to_s
run "chmod #{file.stat.mode.to_s(8)[-3..-1]} #{upload_target}"
end
end
2012-07-04 02:33:16 +00:00
run "cd #{personal_deity_target} && bundle install --path gems"
run "cd #{personal_deity_target} && bundle exec whenever -i god -f schedule.rb"
2012-07-03 21:54:07 +00:00
end
desc "Stop the God service"
task :stop do
2012-07-04 02:33:16 +00:00
run_personal_deity_command :quit
2012-07-03 21:54:07 +00:00
end
desc "Start the God service"
task :start do
2012-07-04 02:33:16 +00:00
run_personal_deity_command
2012-07-03 21:54:07 +00:00
end
desc "Restart the God service"
task :restart do
2012-07-04 02:33:16 +00:00
top.personal_deity.service.stop
top.personal_deity.service.start
2012-07-03 21:54:07 +00:00
end
end
desc "Stop the God process for this application"
task :stop do
2012-07-04 02:33:16 +00:00
run_personal_deity_command :stop, application
2012-07-03 21:54:07 +00:00
end
desc "Start the God process for this application"
task :start do
2012-07-04 02:33:16 +00:00
run_personal_deity_command :start, application
2012-07-03 21:54:07 +00:00
end
desc "Restart the God process for this application"
task :restart do
2012-07-04 02:33:16 +00:00
run_personal_deity_command :restart, application
2012-07-03 21:54:07 +00:00
end
end
2012-07-04 02:33:16 +00:00
before 'deploy:update_symlink', 'personal_deity:install'
before 'deploy:symlink', 'personal_deity:install'
2012-07-03 21:54:07 +00:00
namespace :deploy do
2012-07-04 02:33:16 +00:00
task(:stop) { top.personal_deity.stop }
task(:start) { top.personal_deity.start }
task(:restart) { top.personal_deity.restart }
2012-07-03 21:54:07 +00:00
end
end