capistrano 部署后自动重启服务器
Auto restart the server after capistrano deploy
我有 nginx + nginx 单元 + 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
使用最新版本,您可以重新启动应用程序并让 Unit 从工作目录重新加载代码。
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 集成。
我有 nginx + nginx 单元 + 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
使用最新版本,您可以重新启动应用程序并让 Unit 从工作目录重新加载代码。
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 集成。