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, "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
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
With the latest release you are able to restart the application and let Unit reload the code from the 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
Happy to discuss the capistrano intergration a little further.