From 266408e23599a27ea196fbd4cdfd3ec1ea1f2871 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Thu, 23 May 2024 18:51:16 +0200 Subject: [PATCH 1/7] do not enable a service disabled by the user --- helpers/systemd | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/helpers/systemd b/helpers/systemd index 765c575eff..f657386bd6 100644 --- a/helpers/systemd +++ b/helpers/systemd @@ -25,7 +25,10 @@ ynh_add_systemd_config() { ynh_add_config --template="$template" --destination="/etc/systemd/system/$service.service" - systemctl enable $service --quiet + # do not enable a service disabled by the user + if ! yunohost service status $service | grep -q "start_on_boot: disabled"; then + systemctl enable $service --quiet + fi systemctl daemon-reload } @@ -88,6 +91,11 @@ ynh_systemd_action() { return 0 fi + # do not start a service disabled by the user + if [ "$action" == "start" ] && ! yunohost service status $service_name | grep -q "start_on_boot: disabled"; then + return 0 + fi + # Start to read the log if [[ -n "$line_match" ]]; then local templog="$(mktemp)" From 95250230bc52f60caee0ea3ebf57631c2d2b8280 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Thu, 23 May 2024 19:01:54 +0200 Subject: [PATCH 2/7] also handle 'reload_or_restart' and 'restart' --- helpers/systemd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helpers/systemd b/helpers/systemd index f657386bd6..5c19610db7 100644 --- a/helpers/systemd +++ b/helpers/systemd @@ -92,7 +92,8 @@ ynh_systemd_action() { fi # do not start a service disabled by the user - if [ "$action" == "start" ] && ! yunohost service status $service_name | grep -q "start_on_boot: disabled"; then + if [ "$action" == "start" ] || [ "$action" == "reload_or_restart" ] || [ "$action" == "restart" ] && \ + ! yunohost service status $service_name | grep -q "start_on_boot: disabled"; then return 0 fi From 8bdaedfde749ec3ca21e879d422d5183ed82e418 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Thu, 23 May 2024 23:51:02 +0200 Subject: [PATCH 3/7] Update helpers/systemd Co-authored-by: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> --- helpers/systemd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helpers/systemd b/helpers/systemd index 5c19610db7..eb73f81871 100644 --- a/helpers/systemd +++ b/helpers/systemd @@ -92,8 +92,9 @@ ynh_systemd_action() { fi # do not start a service disabled by the user - if [ "$action" == "start" ] || [ "$action" == "reload_or_restart" ] || [ "$action" == "restart" ] && \ - ! yunohost service status $service_name | grep -q "start_on_boot: disabled"; then + if ([ "$action" == "start" ] || [ "$action" == "reload_or_restart" ] || [ "$action" == "restart" ]) && \ + ! systemctl --quiet is-enabled $service_name; then + echo "$service_name is disabled, therefore skipping action $action" return 0 fi From e8c6abb76871f853bf9561382123faea4e16caea Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Thu, 23 May 2024 23:53:47 +0200 Subject: [PATCH 4/7] Update helpers/systemd Co-authored-by: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> --- helpers/systemd | 4 ---- 1 file changed, 4 deletions(-) diff --git a/helpers/systemd b/helpers/systemd index eb73f81871..7687b15ab2 100644 --- a/helpers/systemd +++ b/helpers/systemd @@ -25,10 +25,6 @@ ynh_add_systemd_config() { ynh_add_config --template="$template" --destination="/etc/systemd/system/$service.service" - # do not enable a service disabled by the user - if ! yunohost service status $service | grep -q "start_on_boot: disabled"; then - systemctl enable $service --quiet - fi systemctl daemon-reload } From cfcbeb3fa9e2a031d0571d0c5d9dd4feecdbd6f8 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 24 May 2024 00:06:03 +0200 Subject: [PATCH 5/7] enable the $app service during install --- helpers/systemd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helpers/systemd b/helpers/systemd index 7687b15ab2..1df6a6fc94 100644 --- a/helpers/systemd +++ b/helpers/systemd @@ -25,6 +25,10 @@ ynh_add_systemd_config() { ynh_add_config --template="$template" --destination="/etc/systemd/system/$service.service" + if [[ ${YNH_APP_ACTION} == "install" ]]; then + systemctl enable $service --quiet + fi + systemctl daemon-reload } From 66f8e31260fb66830d74a8cc8c6b003b83a36152 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sat, 29 Jun 2024 20:59:41 +0200 Subject: [PATCH 6/7] automatically ignore the service in diagnosis if it has been deactivated with the ynh cli --- src/service.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/service.py b/src/service.py index 5e49dfc8a0..8238e41f8e 100644 --- a/src/service.py +++ b/src/service.py @@ -26,6 +26,7 @@ from datetime import datetime from moulinette import m18n +from yunohost.utils.diagnosis import diagnosis_ignore, diagnosis_unignore from yunohost.utils.error import YunohostError, YunohostValidationError from moulinette.utils.process import check_output from moulinette.utils.log import getActionLogger @@ -296,6 +297,9 @@ def service_enable(names): names = [names] for name in names: if _run_service_command("enable", name): + services = _get_services() + if name in services: + diagnosis_unignore({"services": [{"service": name}]}) logger.success(m18n.n("service_enabled", service=name)) else: raise YunohostError( @@ -315,6 +319,9 @@ def service_disable(names): names = [names] for name in names: if _run_service_command("disable", name): + services = _get_services() + if name in services: + diagnosis_ignore({"services": [{"service": name}]}) logger.success(m18n.n("service_disabled", service=name)) else: raise YunohostError( From c410b70b31f561dabd85de8cfee9260e6d19c841 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sat, 29 Jun 2024 21:00:53 +0200 Subject: [PATCH 7/7] Revert "automatically ignore the service in diagnosis if it has been deactivated with the ynh cli" This reverts commit ff78f3ada7c118869a7b1d8dfc07e1b6894dcc83. --- src/service.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/service.py b/src/service.py index 8238e41f8e..5e49dfc8a0 100644 --- a/src/service.py +++ b/src/service.py @@ -26,7 +26,6 @@ from datetime import datetime from moulinette import m18n -from yunohost.utils.diagnosis import diagnosis_ignore, diagnosis_unignore from yunohost.utils.error import YunohostError, YunohostValidationError from moulinette.utils.process import check_output from moulinette.utils.log import getActionLogger @@ -297,9 +296,6 @@ def service_enable(names): names = [names] for name in names: if _run_service_command("enable", name): - services = _get_services() - if name in services: - diagnosis_unignore({"services": [{"service": name}]}) logger.success(m18n.n("service_enabled", service=name)) else: raise YunohostError( @@ -319,9 +315,6 @@ def service_disable(names): names = [names] for name in names: if _run_service_command("disable", name): - services = _get_services() - if name in services: - diagnosis_ignore({"services": [{"service": name}]}) logger.success(m18n.n("service_disabled", service=name)) else: raise YunohostError(