namespace :nginx do %w(start stop restart reload).each do |task_name| desc "#{task } Nginx" task task_name do on roles(:app), in: :sequence, wait: 5 do sudo "systemctl #{task_name} nginx" end end end desc "Remove default Nginx Virtual Host" task "remove_default_vhost" do on roles(:app) do %w(/etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/000-default).each do |default_filename| if test("[ -f #{default_filename} ]") sudo "rm #{default_filename}" puts "Removed default Nginx Virtualhost: #{default_filename}" else puts "Default: #{default_filename} not found, not removed" end end end end end