Commit 2df3a3d6 by Czémán Arnold

Add and apply systemd detector function

parent 1176a7a8
......@@ -5,7 +5,7 @@ import json
import logging
from utils import (ns_exec, sudo, ADDRESSES, get_network_type,
dhcp_no_free_re, dhcp_ack_re)
dhcp_no_free_re, dhcp_ack_re, is_there_systemd)
DHCP_LOGFILE = getenv('DHCP_LOGFILE', '/var/log/syslog')
VLAN_CONF = getenv('VLAN_CONF', 'vlan.conf')
......@@ -77,8 +77,8 @@ def reload_firewall_vlan(data, save_config=True):
def reload_dhcp(data):
with open('/etc/dhcp/dhcpd.conf.generated', 'w') as f:
f.write("\n".join(data) + "\n")
import platform
if platform.dist()[0]=="centos":
if is_there_systemd():
sudo(('/bin/systemctl', 'restart','dhcpd'))
else:
sudo(('/etc/init.d/isc-dhcp-server', 'restart'))
......
import os
from os import getenv
import subprocess as sp
import logging
......@@ -60,3 +61,17 @@ def ns_exec(args, stdin=None):
else:
return sudo(('/sbin/ip', 'netns', 'exec',
NETNS) + args, stdin)
def is_there_systemd():
devnull=open(os.devnull,"w")
try:
sp.call(["/bin/systemctl","--version"],stdout=devnull,stderr=devnull)
except OSError:
devnull.close()
return False
devnull.close()
return True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment