Capistrano 3:部署后不是 "refreshed" 代码(网站保持部署前状态)
Capistrano 3: After deployment is not "refreshed" code (website stays as prior the deploy)
我在网站上做了一些修改(纯HTML+CSS),部署到服务器上,刷新浏览器后内容是一样的。
于是我登陆服务器,杀了独角兽,手动启动,新内容终于出现了。
如何自动执行此操作?
目前,我有这个 deploy.rb
设置:
# config valid only for current version of Capistrano
lock "3.8.1"
set :application, "project"
set :repo_url, "git@bitbucket.org:username/project.git"
set :branch, "master"
set :tmp_dir, '/home/deployer/tmp'
set :deploy_to, "/home/deployer/apps/project"
set :keep_releases, 5
set(:executable_config_files, %w(
unicorn_init.sh
))
# files which need to be symlinked to other parts of the
# filesystem. For example nginx virtualhosts, log rotation
# init scripts etc.
set(:symlinks, [
{
source: "nginx.conf",
link: "/etc/nginx/sites-enabled/default"
},
{
source: "unicorn_init.sh",
link: "/etc/init.d/unicorn_#{fetch(:application)}"
},
{
source: "log_rotation",
link: "/etc/logrotate.d/#{fetch(:application)}"
},
{
source: "monit",
link: "/etc/monit/conf.d/#{fetch(:application)}.conf"
}
])
namespace :deploy do
desc 'Restart application'
task :restart do
task :restart do
invoke 'unicorn:reload'
end
end
after :publishing, :restart
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:web) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
before "deploy", "deploy:check_revision"
end
为了不需要手动重启服务器,我还需要添加什么?
谢谢
您可以创建一个任务来为您执行此重新启动步骤,并在部署过程之后调用它。也许它可以 运行 一个 shell 脚本,其中包含重新启动 Unicorn 所需的命令。将您使用的命令放入脚本中,并通过 Capistrano 任务调用它。像这样:
desc 'Restarts the application calling the appropriate Unicorn shell script.'
task :restart_unicorn do
on roles(:app) do
execute '/etc/init.d/restart_unicorn.sh'
end
end
after 'deploy:published', 'restart_unicorn'
更多详细信息here。不要忘记修改 shell 文件权限以允许执行。任务代码可以在您的 deploy.rb
文件中,但我建议将其移至特定的 Capistrano 任务文件以保持您的代码井井有条。希望这对您有所帮助!
PS.: 也看看Capistrano flow。实际上,您可以在流程的任何部分之前或之后为 运行 创建任务。
我在网站上做了一些修改(纯HTML+CSS),部署到服务器上,刷新浏览器后内容是一样的。
于是我登陆服务器,杀了独角兽,手动启动,新内容终于出现了。
如何自动执行此操作?
目前,我有这个 deploy.rb
设置:
# config valid only for current version of Capistrano
lock "3.8.1"
set :application, "project"
set :repo_url, "git@bitbucket.org:username/project.git"
set :branch, "master"
set :tmp_dir, '/home/deployer/tmp'
set :deploy_to, "/home/deployer/apps/project"
set :keep_releases, 5
set(:executable_config_files, %w(
unicorn_init.sh
))
# files which need to be symlinked to other parts of the
# filesystem. For example nginx virtualhosts, log rotation
# init scripts etc.
set(:symlinks, [
{
source: "nginx.conf",
link: "/etc/nginx/sites-enabled/default"
},
{
source: "unicorn_init.sh",
link: "/etc/init.d/unicorn_#{fetch(:application)}"
},
{
source: "log_rotation",
link: "/etc/logrotate.d/#{fetch(:application)}"
},
{
source: "monit",
link: "/etc/monit/conf.d/#{fetch(:application)}.conf"
}
])
namespace :deploy do
desc 'Restart application'
task :restart do
task :restart do
invoke 'unicorn:reload'
end
end
after :publishing, :restart
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:web) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
before "deploy", "deploy:check_revision"
end
为了不需要手动重启服务器,我还需要添加什么?
谢谢
您可以创建一个任务来为您执行此重新启动步骤,并在部署过程之后调用它。也许它可以 运行 一个 shell 脚本,其中包含重新启动 Unicorn 所需的命令。将您使用的命令放入脚本中,并通过 Capistrano 任务调用它。像这样:
desc 'Restarts the application calling the appropriate Unicorn shell script.'
task :restart_unicorn do
on roles(:app) do
execute '/etc/init.d/restart_unicorn.sh'
end
end
after 'deploy:published', 'restart_unicorn'
更多详细信息here。不要忘记修改 shell 文件权限以允许执行。任务代码可以在您的 deploy.rb
文件中,但我建议将其移至特定的 Capistrano 任务文件以保持您的代码井井有条。希望这对您有所帮助!
PS.: 也看看Capistrano flow。实际上,您可以在流程的任何部分之前或之后为 运行 创建任务。