lib/mascherano/tasks/upstart.cap in mascherano-1.1.0 vs lib/mascherano/tasks/upstart.cap in mascherano-1.2.0

- old
+ new

@@ -1,42 +1,48 @@ -def build_cmd(service_name, action, sudo = false) - cmd = "service #{service_name} #{action}" - cmd = "sudo " + cmd if sudo - cmd -end - namespace :upstart do desc "Start the application services" task :start do - on roles(fetch(:upstart_roles)) do - execute build_cmd(fetch(:upstart_service), 'start', fetch(:upstart_sudo)) + on fetch(:upstart_servers) do + execute fetch(:upstart_cmd), 'start', fetch(:upstart_service) end end desc "Stop the application services" task :stop do - on roles(fetch(:upstart_roles)) do - execute build_cmd(fetch(:upstart_service), 'stop', fetch(:upstart_sudo)) + on fetch(:upstart_servers) do + execute fetch(:upstart_cmd), 'stop', fetch(:upstart_service) end end desc "Restart the application services" task :restart do - on roles(fetch(:upstart_roles)) do - cmd_sq = build_cmd(fetch(:upstart_service), 'start', fetch(:upstart_sudo)) - cmd_sq += ' || ' - cmd_sq += build_cmd(fetch(:upstart_service), 'restart', fetch(:upstart_sudo)) + on fetch(:upstart_servers) do + unless test(fetch(:upstart_cmd), 'start', fetch(:upstart_service)) + execute fetch(:upstart_cmd), 'restart', fetch(:upstart_service) + end + end + end - execute cmd_sq + desc "Prefixes the upstart command with sudo when :upstart_sudo => true" + task :configure_sudo do + if fetch(:upstart_sudo) + upstart_cmd = fetch(:upstart_cmd).to_s + SSHKit.config.command_map.prefix[upstart_cmd].push('sudo') end end end +Capistrano::DSL.stages.each do |stage| + after stage, 'upstart:configure_sudo' +end + namespace :load do task :defaults do - set :upstart_service, -> { fetch(:application) } - set :upstart_sudo, false - set :upstart_roles, :app + set :upstart_service, -> { fetch(:application) } + set :upstart_sudo, false + set :upstart_roles, :app + set :upstart_servers, -> { release_roles(fetch(:upstart_roles)) } + set :upstart_cmd, 'initctl' end end namespace :deploy do after :publishing, 'upstart:restart'