Search code examples
ruby-on-railsruby-on-rails-4ubuntucapistranocapistrano3

Terminal keeps listening to custom task after Capistrano deploy. How we detach without killing?


I'm learning how to deploy with Capistrano and I found out how to run a custom task after deploy. In this case I created the chat task and I run it when deploy is finished:

namespace :deploy do

    desc 'Restart application'
    task :restart do
        on roles(:app) do
            execute 'sudo nginx -s reload'
        end
    end

    task :chat do
        on roles(:app) do
            execute 'sudo kill $(sudo lsof -t -i:4543) ; cd /home/linux/myapp/current ; RAILS_ENV=production rackup private_pub.ru -o 0.0.0.0 -s thin -p 4543 -E production'
        end
    end

    after :publishing, :restart
    after "deploy", "deploy:chat"

end

This starts the server at port 4543 and everything is working well. Except for the fact that this window is not stuck at that process and if I leave I kill it.

enter image description here

What can I do to detach the console instance that run that task from the process in the server?!


Solution

  • The situation is that I have a machine in Amazon EC2 and I make ssh connections to manage it.

    I gave up trying to use Capistrano for this.

    Well the solution I found to detach the program and then return to the main terminal was the tmux tool. I had to install it and then run the tmux command on terminal, run my command when tmux is open and then CTRL+B to exit the tmux layer. The task keeps running.