Created
May 22, 2012 15:20
-
-
Save jeroenr/2769718 to your computer and use it in GitHub Desktop.
Deploying play2 application with capistrano
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :deploy_to, "/usr/share/my-app" | |
namespace :play do | |
task :setup do | |
run "mkdir -p #{deploy_to}" | |
upload "my-app/start.sh", "#{deploy_to}/start.sh", :mode => '755', :via => :scp | |
upload "my-app/stop.sh", "#{deploy_to}/stop.sh", :mode => '755', :via => :scp | |
end | |
task :deploy do | |
package | |
stop | |
copy_app_files | |
start_prod | |
end | |
task :stop do | |
targets = find_servers_for_task(current_task) | |
failed_targets = targets.map do |target| | |
cmd = "ssh #{user}@#{target.host} 'cd #{deploy_to} && ./stop.sh'" | |
target.host unless system cmd | |
end.compact | |
raise "Stopping my-app failed on #{failed_targets.join(',')}" if failed_targets.any? | |
end | |
task :start do | |
targets = find_servers_for_task(current_task) | |
failed_targets = targets.map do |target| | |
cmd = "ssh #{user}@#{target.host} 'cd #{deploy_to} && ./start.sh -Dconfig.resource=prod.conf'" | |
target.host unless system cmd | |
end.compact | |
raise "Starting my-app failed on #{failed_targets.join(',')}" if failed_targets.any? | |
end | |
task :package do | |
system "cd my-app && play clean compile stage" | |
end | |
task :copy_app_files do | |
upload "my-app/target", deploy_to, :via => :scp, :recursive => true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: play framework | |
# Required-Start: $syslog $time $remote_fs | |
# Required-Stop: $syslog $time $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Play application | |
# Description: Play application | |
### END INIT INFO | |
. /lib/lsb/init-functions | |
USER="jeroenr" | |
MY_APP_DIR="/usr/share/my-app" | |
PIDFILE="$MY_APP_DIR/RUNNING_PID" | |
case $1 in | |
start) | |
su - $USER -c "cd $MY_APP_DIR && exec ./start.sh -Dconfig.resource=prod.conf" | |
exit 0 | |
;; | |
stop) | |
su - $USER -c "cd $MY_APP_DIR && exec ./stop.sh" | |
exit 0 | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
PID=$(cat $PIDFILE 2> /dev/null) | |
if [ "$PID" != "" ] && [ -d /proc/$PID ]; then echo "My-app is running"; exit 0; fi | |
echo "My-app is NOT running!" | |
exit 1 | |
;; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
nohup bash -c "cd /home/elmar/my-app && target/start $* &>> /var/log/my-app.log 2>&1" &> /dev/null & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pid=`cat RUNNING_PID 2> /dev/null` | |
if [ "$pid" == "" ]; then echo "trip-api is not running"; exit 0; fi | |
echo "Stopping trip-api..." | |
kill -SIGTERM $pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe I'll transform it into a capistrano plugin one day