Capistrano 3:部署后没有“刷新”代码(网站保持部署之前)

时间:2017-07-27 14:21:12

标签: ruby ruby-on-rails-3 nginx capistrano unicorn

我正在对网站进行一些修改(纯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

为了不需要手动重启服务器,还需要添加什么?

谢谢

1 个答案:

答案 0 :(得分:1)

您可以创建一个为您执行此重新启动步骤的任务,并在部署过程之后调用它。也许它可以运行带有重启Unicorn所需命令的shell脚本。将您使用的命令放在脚本中,然后通过Capistrano任务调用它。像这样:

var docTitle = document.title();
    docTitle.match(regex);

更多详情here。不要忘记修改shell文件权限以允许执行。任务代码可以在您的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' 文件中,但我建议将其移至特定的Capistrano任务文件以保持代码的有序性。希望这有帮助!

PS:看看Capistrano flow。实际上,您可以创建在流程的任何部分之前或之后运行的任务。