Issue
I know this question has been asked a lot, but I cannot manage to get it right. I have already looked at :
- href="https://stackoverflow.com/questions/1109274/starting-background-tasks-with-capistrano">Starting background tasks with Capistrano
- launching background process in capistrano task
- http://whowish-programming.blogspot.fr/2011/04/run-background-process-with-capistrano.html
I am using capistrano to deploy a server in scala. My task looks like this :
desc "Start server"
task :start do
run "cd #{deploy_to} && ./sbt compile start-script"
run "cd #{deploy_to} && export PORT=#{server_port} && export ENV=#{env} && nohup target/start > /dev/null 2>&1 &"
end
start-script is an sbt plugin that creates a script in target/start. When I run the task, the output is :
* executing "cd /home/ubuntu/* && export PORT=* && export ENV=integration && nohup target/start > /dev/null 2>&1 &"
servers: ["54.217.224.197"]
[54.217.224.197] executing command
command finished in 1015ms
but my server is not started... When omitting the "&" at the end of the command, the server is started but the capistrano script is blocked.
* executing "cd /home/ubuntu/* && export PORT=* && export ENV=integration && nohup target/start > /dev/null 2>&1"
servers: ["54.217.224.197"]
[54.217.224.197] executing command
Thanks in advance for your answers.
Solution
I found a solution, just add pty: false at the end
run "cd #{deploy_to} && export PORT=#{server_port} && export ENV=#{env} && nohup target/start > /dev/null 2>&1 &" pty: false
Answered By - Benoit Guigal Answer Checked By - David Marino (WPSolving Volunteer)