Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
Add cap process Restart 29hours
Browse files Browse the repository at this point in the history
  • Loading branch information
masutaka committed Jul 25, 2015
1 parent d8dd703 commit 06b35bd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
10 changes: 9 additions & 1 deletion config/deploy.rb
Expand Up @@ -26,7 +26,7 @@
# set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')

# Default value for linked_dirs is []
set :linked_dirs, %w{29hours/vendor/bundle}
set :linked_dirs, %w{29hours/log 29hours/tmp/pids 29hours/vendor/bundle}

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
Expand All @@ -46,4 +46,12 @@
capture "cd #{release_path}/29hours && curl -Ls -o settings.yml #{ENV.fetch('SETTINGS_FILE_PATH')}"
end
end

desc 'Restart 29hours'
after :publishing, :restart do
on roles(:app) do
invoke 'twenty_nine_hours:stop'
invoke 'twenty_nine_hours:start'
end
end
end
45 changes: 45 additions & 0 deletions lib/capistrano/tasks/twenty_nine_hours.rake
@@ -0,0 +1,45 @@
namespace :load do
task :defaults do
set :twenty_nine_hours_log, -> { shared_path.join('29hours', 'log', '29hours.log') }
set :twenty_nine_hours_pid, -> { shared_path.join('29hours', 'tmp', 'pids', '29hours.pid') }
end
end

namespace :twenty_nine_hours do
desc 'Start 29hours'
task :start do
on roles(:app) do
within current_path.join('29hours') do
if test("[ -e #{fetch(:twenty_nine_hours_pid)} ] && kill -0 #{twenty_nine_hours_pid}")
info '29hours is running...'
else
execute :bundle, 'exec ruby 29hours.rb --production >>', fetch(:twenty_nine_hours_log), '2>&1 &; echo $! > ', fetch(:twenty_nine_hours_pid)
end
end
end
end

desc 'Stop 29hours'
task :stop do
on roles(:app) do
within current_path.join('29hours') do
if test("[ -e #{fetch(:twenty_nine_hours_pid)} ]")
if test("kill -0 #{twenty_nine_hours_pid}")
info 'stopping 29hours...'
execute :kill, twenty_nine_hours_pid
execute :rm, fetch(:twenty_nine_hours_pid)
else
info 'cleaning up dead 29hours pid...'
execute :rm, fetch(:twenty_nine_hours_pid)
end
else
info '29hours is not running...'
end
end
end
end

def twenty_nine_hours_pid
"`cat #{fetch(:twenty_nine_hours_pid)}`"
end
end

0 comments on commit 06b35bd

Please sign in to comment.