From e15d8e72624b225840713abf5e801be7e2c07ccf Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 5 Nov 2019 21:52:35 +0100 Subject: [PATCH] Add test about configuration validity --- data/templates/yunohost/services.yml | 3 +++ src/yunohost/service.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/data/templates/yunohost/services.yml b/data/templates/yunohost/services.yml index a9948fc69..fd9d06eac 100644 --- a/data/templates/yunohost/services.yml +++ b/data/templates/yunohost/services.yml @@ -1,5 +1,6 @@ nginx: log: /var/log/nginx + test-conf: nginx -t avahi-daemon: log: /var/log/daemon.log dnsmasq: @@ -20,12 +21,14 @@ mysql: alternates: ['mariadb'] ssh: log: /var/log/auth.log + test-conf: sshd -t metronome: log: [/var/log/metronome/metronome.log,/var/log/metronome/metronome.err] slapd: log: /var/log/syslog php7.0-fpm: log: /var/log/php7.0-fpm.log + test-conf: php-fpm7.0 --test yunohost-api: log: /var/log/yunohost/yunohost-api.log yunohost-firewall: diff --git a/src/yunohost/service.py b/src/yunohost/service.py index 96a7061e3..8f1e55669 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -297,6 +297,7 @@ def service_status(names=[]): 'active_at': "unknown", 'description': "Error: failed to get information for this service, it doesn't exists for systemd", 'service_file_path': "unknown", + 'configuration': "unknown", } else: @@ -318,6 +319,7 @@ def service_status(names=[]): 'active': str(status.get("ActiveState", "unknown")), 'description': description, 'service_file_path': str(status.get("FragmentPath", "unknown")), + 'configuration': "unknown", } # Fun stuff™ : to obtain the enabled/disabled status for sysv services, @@ -335,6 +337,11 @@ def service_status(names=[]): status = os.system(services[name]["test-status"]) result[name]["status"] = "running" if status == 0 else "failed" + # 'test-status' is an optional field to test the status of the service using a custom command + if "test-conf" in services[name]: + conf = os.system(services[name]["test-conf"] + " &>/dev/null") + result[name]["configuration"] = "valid" if conf == 0 else "broken" + if len(names) == 1: return result[names[0]] return result