@@ -32,16 +32,22 @@ func EnforceLogging(cfg LogConfig, log *zap.SugaredLogger) {
32
32
return
33
33
}
34
34
log .Error (errw .Wrapf (err , "deleting %s" , journaldConfPath ))
35
+ return
36
+ }
37
+
38
+ if ! checkJournaldEnabled (log ) {
39
+ return
40
+ }
41
+
42
+ if err := restartJournald (); err != nil {
43
+ log .Error (err )
44
+ return
35
45
}
36
46
log .Infof ("Logging config disabled. Removing customized %s" , journaldConfPath )
37
47
return
38
48
}
39
49
40
- cmd := exec .Command ("systemctl" , "is-enabled" , "systemd-journald" )
41
- output , err := cmd .CombinedOutput ()
42
- if err != nil {
43
- log .Error (errw .Wrapf (err , "executing 'systemctl is-enabled systemd-journald' %s" , output ))
44
- log .Error ("agent-syscfg can only adjust logging settings for systems using systemd with journald enabled" )
50
+ if ! checkJournaldEnabled (log ) {
45
51
return
46
52
}
47
53
@@ -86,12 +92,30 @@ func EnforceLogging(cfg LogConfig, log *zap.SugaredLogger) {
86
92
}
87
93
88
94
if isNew {
89
- cmd = exec .Command ("systemctl" , "restart" , "systemd-journald" )
90
- output , err = cmd .CombinedOutput ()
91
- if err != nil {
92
- log .Error (errw .Wrapf (err , "executing 'systemctl restart systemd-journald' %s" , output ))
95
+ if err := restartJournald (); err != nil {
96
+ log .Error (err )
93
97
return
94
98
}
95
99
log .Infof ("Updated %s, setting SystemMaxUse=%s and RuntimeMaxUse=%s" , journaldConfPath , persistSize , tempSize )
96
100
}
97
101
}
102
+
103
+ func restartJournald () error {
104
+ cmd := exec .Command ("systemctl" , "restart" , "systemd-journald" )
105
+ output , err := cmd .CombinedOutput ()
106
+ if err != nil {
107
+ return errw .Wrapf (err , "executing 'systemctl restart systemd-journald' %s" , output )
108
+ }
109
+ return nil
110
+ }
111
+
112
+ func checkJournaldEnabled (log * zap.SugaredLogger ) bool {
113
+ cmd := exec .Command ("systemctl" , "is-enabled" , "systemd-journald" )
114
+ output , err := cmd .CombinedOutput ()
115
+ if err != nil {
116
+ log .Error (errw .Wrapf (err , "executing 'systemctl is-enabled systemd-journald' %s" , output ))
117
+ log .Error ("agent-syscfg can only adjust logging settings for systems using systemd with journald enabled" )
118
+ return false
119
+ }
120
+ return true
121
+ }
0 commit comments