0

我有 nginx + nginx unit + django python 应用程序,django 项目是由capistrano

deploy.rb

lock "~> 3.16.0"

set :application, "mynavi"
set :branch, 'master'
set :deploy_to, "/var/www/html/mynavi"

set :linked_dirs, fetch(:linked_dirs, []).push('static')
set :keep_releases, 3

set :linked_files,  %w{.env}

set :repo_url, "ubuntu@git.example.jp:/~/myGit/mynavi.git"

production.rb

set :stage, :production
set :branch, 'master'
server 'lion.example.jp', user: 'ubuntu', roles: %w(app), primary: true
namespace :deploy do
    desc 'Collec Static Files'
    task :collectImg do
        on roles(:app) do
            execute "source activate mynavi;/home/ubuntu/anaconda3/envs/mynavi/bin/python /var/www/html/mynavi/current/manage.py collectstatic --noinput"
        end
    end
    after :publishing, :collectImg
end

cap prodution deploy使部署成功

但是,部署后

我需要unit手动重启。

sudo systemctl restart unit

我可以在部署后自动执行此操作吗?


解决方案

感谢@Timo Stark 的回答

我最终的 production.rb 在这里,只是添加了卷曲线。

production.rb

set :stage, :production
set :branch, 'master'
server 'lion.example.jp', user: 'ubuntu', roles: %w(app), primary: true
namespace :deploy do
    desc 'Collec Static Files'
    task :collectImg do
        on roles(:app) do
            execute "source activate mynavi;/home/ubuntu/anaconda3/envs/mynavi/bin/python /var/www/html/mynavi/current/manage.py collectstatic --noinput"
            execute "sudo curl -X GET --unix-socket /path/to/control.unit.sock http://localhost/control/applications/app_name/restart"
        end
    end
    after :publishing, :collectImg
end
4

1 回答 1

1

使用最新版本,您可以重新启动应用程序并让 Unit 从 workdir 重新加载代码。

sudo curl -X GET --unix-socket /path/to/control.unit.sock  \
      http://localhost/control/applications/app_name/restart

https://unit.nginx.org/configuration/#process-management

很高兴进一步讨论 capistrano 的集成。

于 2022-02-25T17:46:43.833 回答