How to run play2 application on a remote computer using capistrano
I am trying to deploy play2 application with capistrano, but I cannot figure out how to (re) start play2 application after successful deployment. Just starting βstart playbackβ will cause the process to hang, waiting for me to press Ctrl + D
I created a start script in the root folder of the playback application
#!/bin/bash nohup bash -c "/var/lib/play2/play start &>> /tmp/myapp.log 2>&1" &> /dev/null &
It works great when I run it on the server. When I try to call this from my local machine on top of ssh, it also works. But when I use capistrano, it does not seem to do anything. My capistrano configuration looks like this:
namespace :deploy do task :restart do stop sleep 1 start end task :start do run "cd #{current_release}/trip-api && ./start.sh" end task :stop do run "cd #{current_release}/trip-api && ./stop.sh" end end
What is the best way to run play2 application on a remote computer? How to make it work with capistrano?
See the documentation for the game application deployment in production
The recommended way is to pack your application with
play clean compile stage
And then run it with
$ target / start
To stop it, view the docs:
The server process identifier is displayed in the bootstrap and written to the RUNNING_PID file. To kill a running playback server, just send SIGTERM to correctly terminate the application.
In this quickstart for Openshift, he shows another way to start the game as a service and how to stop it .
basically you do something like this to get started:
APP_COMMAND="${OPENSHIFT_REPO_DIR}target/start $PLAY_PARAMS "\ "-Dhttp.port=${OPENSHIFT_INTERNAL_PORT} "\ "-Dhttp.address=${OPENSHIFT_INTERNAL_IP} "\ "-Dconfig.resource=openshift.conf" echo $APP_COMMAND &>> $LOG_FILE nohup bash -c "${APP_COMMAND} &>> ${LOG_FILE} 2>&1" &> /dev/null &
and stop him
pid=`cat RUNNING_PID` echo "Stopping play application" >> $LOG_FILE kill -SIGTERM $pid
Google Groups has some fresh topics about launching the app:
- Run the application as a background process
- When deployed to a remote host, Ubuntu 10.04 .
Itβs a good idea to follow or join them.
I would suggest using runit. We currently have a bunch of services in production, and it works great.
This only involves creating a simple script named run shell, pointing runit to its containing directory and then running it. Services should not demonize themselves, but runit manages pid files, etc.
There is a command ( sv
) for starting, stopping and requesting services. ( sv start|stop|status|restart yourapp
).
A quick google search gave me this http://rubygems.org/gems/capistrano-runit , although I don't use capistrano at all, so I can't vouch for its usefulness.
http://smarden.org/runit/
The best place to start is faq: http://smarden.org/runit/faq.html
In debian you are just apt-get install runit
and good to go. update-service --add /your/service/dir/
register the service using runit.
During deployment, we stop the services, modify the binaries, and start the services; it is really simple.