Pratibha Praveen
Pratibha Praveen

Reputation: 111

Running rpush on production using capistrano 3

For running Rpush, I have written this in config/deploy.rb

 after :publishing, 'deploy:restart'

  after :finishing, 'deploy:cleanup'

  after :finished, :restart_rpush do

    on roles(:web) do
        within release_path do
            with rails_env: fetch(:rails_env) do
                execute :bundle, :exec, "rpush stop -e #{fetch(:rails_env)}"
                execute :bundle, :exec, "rpush start -e #{fetch(:rails_env)}"
            end
        end
    end
  end
end

At the time of deployment I am getting this error :

DEBUG [76ef4791]    * Rpush isn't running? 
/home/dev/proteqtor/releases/20150714065629/tmp/rpush.pid does not exist.

Rpush is not running. What could be the cause of this issue?

Upvotes: 2

Views: 814

Answers (1)

Matthew Ager
Matthew Ager

Reputation: 336

I believe that is because, since Rpush is not running, you are getting an uncaught exception to execute :bundle, :exec, "rpush stop -e #{fetch(:rails_env)}". I.e. why run rpush stop if it isn't running?

Instead, first test (using Capistrano 3's test command) whether the pid file exists at the given path and only run stop if it, does and otherwise just run start:

desc 'Restart rpush'
task :restart_rpush do
  on roles(:web) do
    within release_path do
      with rails_env: fetch(:rails_env) do
        if test('[ -f /path/to/my/pid/file ]')
          # Rpush is running
          execute :bundle, :exec, "rpush stop -e #{fetch(:rails_env)}"
          execute :bundle, :exec, "rpush start -e #{fetch(:rails_env)}"
        else
          # Rpush is not running
          execute :bundle, :exec, "rpush start -e #{fetch(:rails_env)}"
        end
      end
    end
  end
end

after :finished, :restart_rpush

Upvotes: 3

Related Questions