问题
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.
回答1:
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
回答2:
What's the error message for the failure?
This works for me:
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app, :web), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
end
after 'deploy:publishing', 'deploy:restart'
回答3:
I've modified the given answer to show the solution that has worked for me.
I've just enter the next lines at the end of the config/deploy.rb
file.
namespace :deploy do
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
after :deploy, "deploy:restart"
after :rollback, "deploy:restart"
end
Doing that, Passenger will restart automatically after each deploy/rollback.
I think it worth mentioning that you can also restart Passenger manually from your development environment each time you run the next line:
cap production deploy:restart
回答4:
On my cap I got a similar error on a multi-server deploy. It seems that the problem is that it is relying on your running a previous rails command (to generate the tmp directory) before restarting, such as db:migrate.
来源:https://stackoverflow.com/questions/22489712/restart-application-no-longer-working-with-cap-3-1-and-rails-4