Skip to content

Instantly share code, notes, and snippets.

@jeroenr
Created May 14, 2012 15:17
Show Gist options
  • Save jeroenr/2694531 to your computer and use it in GitHub Desktop.
Save jeroenr/2694531 to your computer and use it in GitHub Desktop.
Capistrano deployment script for play2 application
namespace :deploy do
task :restart do
stop
sleep 1
start
end
task :start do
targets = find_servers_for_task(current_task)
failed_targets = targets.map do |target|
cmd = "ssh #{user}@#{target.host} 'cd #{current_release}/my-app && ./start.sh'"
target.host unless system cmd
end.compact
raise "starting my play2 app failed on #{failed_targets.join(',')}" if failed_targets.any?
end
task :stop do
targets = find_servers_for_task(current_task)
failed_targets = targets.map do |target|
cmd = "ssh #{user}@#{target.host} 'cd #{current_release}/my-app && ./stop.sh'"
target.host unless system cmd
end.compact
raise "stopping my play2 app failed on #{failed_targets.join(',')}" if failed_targets.any?
end
end
#!/bin/bash
nohup bash -c "/var/lib/play2/play start &>> /tmp/my-app.log 2>&1" &> /dev/null &
#!/bin/bash
pid=`cat RUNNING_PID 2> /dev/null`
if [ "$pid" == "" ]; then echo "my play2 app is not running"; exit 0; fi
echo "Stopping my play2 app..."
kill -SIGTERM $pid
@keith-miller
Copy link

Thanks so much for these two scripts! Finally got this working because of them!

@pathikrit
Copy link

why do you need so many levels deep? why can't we do play start & or maybe just nohup play start &? why make it append to a log, background it using & and then put it in bash and background bash itself??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment