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, "[email protected]:/~/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 部署的生产部署
使部署成功
但是,部署后
我需要手动重新启动单元
。
sudo systemctl restart unit
我可以在部署后自动执行此操作吗?
解决方案
感谢@Timo Stark的回答
我的最终制作.rb在这里,只需添加卷曲线。
生产.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
I have nginx + nginx unit + django python application , and django project is is deployed by 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, "[email protected]:/~/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
makes deployment successfully
However, after deployment
I need to restart unit
manually.
sudo systemctl restart unit
Can I do this automatic after deployment?
Solution
Thanks to @Timo Stark 's answer
My final production.rb is here, just adding the curl line.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用最新版本,您可以重新启动应用程序并让 Unit 从工作目录重新加载代码。
https://unit.nginx.org/configuration/#process-management
快乐进一步讨论 Capistrano 集成。
With the latest release you are able to restart the application and let Unit reload the code from the workdir.
https://unit.nginx.org/configuration/#process-management
Happy to discuss the capistrano intergration a little further.