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

Restart application no longer working with Cap 3.1 and Rails 4


The following task was working before we upgraded to Rails 4 and Cap 3.1

desc 'Restart application'
task :restart do
  on roles(:web), in: :sequence, wait: 5 do
    execute :touch, release_path.join('tmp/restart.txt')
  end
end

First of all, I know Cap 3.1 doesn't implicitly call :restart anymore so I added the following:

after :publishing, :restart

However, it fails on attempting to 'touch' the restart.txt file so that Apache will reload the application.

cap aborted!
touch stdout: Nothing written
touch stderr: Nothing written
config/deploy.rb:46:in `block (3 levels) in <top (required)>'
config/deploy.rb:45:in `block (2 levels) in <top (required)>'
Tasks: TOP => deploy:restart
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Command::Failed: touch stdout: Nothing written
touch stderr: Nothing written
>

Do I still need a restart? It generally seems okay but I'm wondering if there could be issues that come up by not finding a way to do this.


Solution

  • Had a similar issue, tried to run this command on server and got an error touch: cannot touch 'myappdir/releases/20140416074158/tmp/restart.txt': No such file or directory, so I simply added a line to create a release_path/tmp dir:

    desc 'Restart application'
    task :restart do
      on roles(:web), in: :sequence, wait: 5 do
        execute :mkdir, '-p', "#{ release_path }/tmp"
        execute :touch, release_path.join('tmp/restart.txt')
      end
    end