@@ -42,12 +42,15 @@ def obfuscate(data):
42
42
43
43
44
44
def update_feature_state (feature_name , state , has_timer = False ):
45
- feature_suffix = " timer" if has_timer else "service"
45
+ feature_suffixes = [ "service" ] + ([ " timer"] if has_timer else [])
46
46
if state == "enabled" :
47
47
start_cmds = []
48
- start_cmds .append ("sudo systemctl unmask {}.{}" .format (feature_name , feature_suffix ))
49
- start_cmds .append ("sudo systemctl enable {}.{}" .format (feature_name , feature_suffix ))
50
- start_cmds .append ("sudo systemctl start {}.{}" .format (feature_name , feature_suffix ))
48
+ for suffix in feature_suffixes :
49
+ start_cmds .append ("sudo systemctl unmask {}.{}" .format (feature_name , suffix ))
50
+ start_cmds .append ("sudo systemctl enable {}.{}" .format (feature_name , suffix ))
51
+ # If feature has timer associated with it, start corresponding systemd .timer unit
52
+ # otherwise, start corresponding systemd .service unit
53
+ start_cmds .append ("sudo systemctl start {}.{}" .format (feature_name , feature_suffixes [- 1 ]))
51
54
for cmd in start_cmds :
52
55
syslog .syslog (syslog .LOG_INFO , "Running cmd: '{}'" .format (cmd ))
53
56
try :
@@ -56,12 +59,14 @@ def update_feature_state(feature_name, state, has_timer=False):
56
59
syslog .syslog (syslog .LOG_ERR , "'{}' failed. RC: {}, output: {}"
57
60
.format (err .cmd , err .returncode , err .output ))
58
61
continue
59
- syslog .syslog (syslog .LOG_INFO , "Feature '{}.{}' is enabled and started" .format (feature_name , feature_suffix ))
62
+ syslog .syslog (syslog .LOG_INFO , "Feature '{}.{}' is enabled and started"
63
+ .format (feature_name , feature_suffixes [- 1 ]))
60
64
elif state == "disabled" :
61
65
stop_cmds = []
62
- stop_cmds .append ("sudo systemctl stop {}.{}" .format (feature_name , feature_suffix ))
63
- stop_cmds .append ("sudo systemctl disable {}.{}" .format (feature_name , feature_suffix ))
64
- stop_cmds .append ("sudo systemctl mask {}.{}" .format (feature_name , feature_suffix ))
66
+ for suffix in reversed (feature_suffixes ):
67
+ stop_cmds .append ("sudo systemctl stop {}.{}" .format (feature_name , suffix ))
68
+ stop_cmds .append ("sudo systemctl disable {}.{}" .format (feature_name , suffix ))
69
+ stop_cmds .append ("sudo systemctl mask {}.{}" .format (feature_name , suffix ))
65
70
for cmd in stop_cmds :
66
71
syslog .syslog (syslog .LOG_INFO , "Running cmd: '{}'" .format (cmd ))
67
72
try :
@@ -72,8 +77,8 @@ def update_feature_state(feature_name, state, has_timer=False):
72
77
continue
73
78
syslog .syslog (syslog .LOG_INFO , "Feature '{}' is stopped and disabled" .format (feature_name ))
74
79
else :
75
- syslog .syslog (syslog .LOG_ERR , "Unexpected state value '{}' for feature '{}.{} '"
76
- .format (state , feature_name , feature_suffix ))
80
+ syslog .syslog (syslog .LOG_ERR , "Unexpected state value '{}' for feature '{}'"
81
+ .format (state , feature_name ))
77
82
78
83
79
84
class Iptables (object ):
0 commit comments