我有 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