From 418d024ff0805a158a4380cdc856b27f4cedccc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Wed, 17 Feb 2021 17:37:20 +0100 Subject: [PATCH 1/2] Add graceful and graceful-stop tasks --- README.md | 4 +++- lib/capistrano/apache/tasks/systemd.rake | 14 ++++++++++++++ lib/capistrano/apache/tasks/sysv_upstart.rake | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a822693..4579ac4 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,14 @@ Require one of the above 'Environments Supported' in your `Capfile`: require 'capistrano/apache/systemd' ``` -`capistrano/apache` comes with 5 tasks: +`capistrano/apache` comes with 7 tasks: * apache:reload * apache:force_reload * apache:restart +* apache:graceful * apache:stop +* apache:graceful-stop You can execute the task on command line: diff --git a/lib/capistrano/apache/tasks/systemd.rake b/lib/capistrano/apache/tasks/systemd.rake index 404cb58..9ac6b12 100644 --- a/lib/capistrano/apache/tasks/systemd.rake +++ b/lib/capistrano/apache/tasks/systemd.rake @@ -20,6 +20,13 @@ namespace :apache do end end + desc 'Gracefuly stop apache (requires root access to apache stop)' + task :graceful_stop do + on release_roles(fetch(:apache_roles)) do + fetch(:apache_with_sudo) ? execute(:sudo, fetch(:systemctl_location), "graceful-stop #{fetch(:apache_service_name)}.service") : execute(fetch(:systemctl_location), "graceful-stop #{fetch(:apache_service_name)}.service") + end + end + desc 'Start apache (requires root access to apache start)' task :start do on release_roles(fetch(:apache_roles)) do @@ -33,6 +40,13 @@ namespace :apache do fetch(:apache_with_sudo) ? execute(:sudo, fetch(:systemctl_location), "restart #{fetch(:apache_service_name)}.service") : execute(fetch(:systemctl_location), "restart #{fetch(:apache_service_name)}.service") end end + + desc 'Gracefuly restart apache (requires root access to apache restart)' + task :graceful do + on release_roles(fetch(:apache_roles)) do + fetch(:apache_with_sudo) ? execute(:sudo, fetch(:systemctl_location), "graceful #{fetch(:apache_service_name)}.service") : execute(fetch(:systemctl_location), "graceful #{fetch(:apache_service_name)}.service") + end + end end diff --git a/lib/capistrano/apache/tasks/sysv_upstart.rake b/lib/capistrano/apache/tasks/sysv_upstart.rake index 4266171..66adb97 100644 --- a/lib/capistrano/apache/tasks/sysv_upstart.rake +++ b/lib/capistrano/apache/tasks/sysv_upstart.rake @@ -20,6 +20,13 @@ namespace :apache do end end + desc 'Gracefuly stop apache' + task :graceful_stop do + on release_roles(fetch(:apache_roles)) do + fetch(:apache_with_sudo) ? execute(:sudo, "/etc/init.d/#{fetch(:apache_service_name)}", 'graceful-stop') : execute("/etc/init.d/#{fetch(:apache_service_name)}", 'graceful-stop') + end + end + desc 'Start apache' task :start do on release_roles(fetch(:apache_roles)) do @@ -33,4 +40,11 @@ namespace :apache do fetch(:apache_with_sudo) ? execute(:sudo, "/etc/init.d/#{fetch(:apache_service_name)}", 'restart') : execute("/etc/init.d/#{fetch(:apache_service_name)}", 'restart') end end + + desc 'Gracefuly restart apache' + task :graceful do + on release_roles(fetch(:apache_roles)) do + fetch(:apache_with_sudo) ? execute(:sudo, "/etc/init.d/#{fetch(:apache_service_name)}", 'graceful') : execute("/etc/init.d/#{fetch(:apache_service_name)}", 'graceful') + end + end end \ No newline at end of file From 6cd01305a6ee0e98a92c80e965dad24fd8c81571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Wed, 17 Feb 2021 23:32:47 +0100 Subject: [PATCH 2/2] Fix typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4579ac4..5521cea 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ require 'capistrano/apache/systemd' * apache:restart * apache:graceful * apache:stop -* apache:graceful-stop +* apache:graceful_stop You can execute the task on command line: