From 4af48e139cfadee27e93d658a70a7472d643f9e6 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Thu, 22 Oct 2015 22:26:51 +0200 Subject: [PATCH] simpler way to check if systemd is the init system According to http://www.freedesktop.org/software/systemd/man/sd_booted.html check if the directory /run/systemd/system/ exists. --- lib/ansible/modules/system/service.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index f9a8b1e24c1..227d34c1463 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -403,22 +403,7 @@ class LinuxService(Service): self.svc_initscript = initscript def check_systemd(): - # verify systemd is installed (by finding systemctl) - if not location.get('systemctl', False): - return False - - # Check if init is the systemd command, using comm as cmdline could be symlink - try: - f = open('/proc/1/comm', 'r') - except IOError, err: - # If comm doesn't exist, old kernel, no systemd - return False - - for line in f: - if 'systemd' in line: - return True - - return False + return os.path.exists("/run/systemd/system/") # Locate a tool to enable/disable a service if location.get('systemctl',False) and check_systemd():