Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bunch of tasks to achieve more controlled deploys #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions lib/capistrano-unicorn/capistrano_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class CapistranoIntegration
'unicorn:reload',
'unicorn:shutdown',
'unicorn:add_worker',
'unicorn:remove_worker'
'unicorn:remove_worker',
'unicorn:stop_old_master',
'unicorn:duplicate_stop_old_workers',
'unicorn:fallback'
]

def self.load_into(capistrano_config)
Expand Down Expand Up @@ -143,6 +146,17 @@ def unicorn_roles
fetch(:unicorn_roles, :app)
end

def kill_old_unicorn
<<-END
if #{old_unicorn_is_running?}; then
echo "Stopping old Unicorn...";
#{unicorn_send_signal('QUIT', get_old_unicorn_pid)};
else
echo "old Unicorn is not running.";
fi;
END
end

#
# Unicorn cap tasks
#
Expand All @@ -169,12 +183,11 @@ def unicorn_roles

sleep #{unicorn_restart_sleep_time}; # in order to wait for the (old) pidfile to show up

if #{old_unicorn_is_running?}; then
#{unicorn_send_signal('QUIT', get_old_unicorn_pid)};
fi;
#{kill_old_unicorn}
END
end


desc 'Duplicate Unicorn'
task :duplicate, :roles => unicorn_roles, :except => {:no_release => true} do
run duplicate_unicorn()
Expand Down Expand Up @@ -215,6 +228,30 @@ def unicorn_roles
fi;
END
end

desc 'Kill old master process'
task :stop_old_master, :roles => unicorn_roles, :except => {:no_release => true} do
run kill_old_unicorn()
end

desc 'Duplicate unicorn and tell the old master to stop serving requests'
task :duplicate_stop_old_workers, :roles => unicorn_roles, :except => {:no_release => true} do
run <<-END
#{duplicate_unicorn}

sleep #{unicorn_restart_sleep_time};

if #{old_unicorn_is_running?}; then
#{unicorn_send_signal('WINCH', get_old_unicorn_pid)};
fi;
END
end

desc 'Fallback to old master'
task :fallback, :roles => unicorn_roles, :except => {:no_release => true} do
run unicorn_send_signal('HUP', get_old_unicorn_pid)
end

end
end
end
Expand Down