@@ -15,7 +15,21 @@ import (
15
15
// reloaded, all sockets systemd listens on behalf of user configuration will
16
16
// stay accessible.
17
17
func DaemonReload (ctx context.Context , opts Options ) error {
18
- var args = []string {"daemon-reload" , "--system" }
18
+ args := []string {"daemon-reload" , "--system" }
19
+ if opts .UserMode {
20
+ args [1 ] = "--user"
21
+ }
22
+ _ , _ , _ , err := execute (ctx , args )
23
+ return err
24
+ }
25
+
26
+ // Reenables one or more units.
27
+ //
28
+ // This removes all symlinks to the unit files backing the specified units from
29
+ // the unit configuration directory, then recreates the symlink to the unit again,
30
+ // atomically. Can be used to change the symlink target.
31
+ func Reenable (ctx context.Context , unit string , opts Options ) error {
32
+ args := []string {"reenable" , "--system" , unit }
19
33
if opts .UserMode {
20
34
args [1 ] = "--user"
21
35
}
@@ -29,7 +43,7 @@ func DaemonReload(ctx context.Context, opts Options) error {
29
43
// the unit configuration directory, and hence undoes any changes made by
30
44
// enable or link.
31
45
func Disable (ctx context.Context , unit string , opts Options ) error {
32
- var args = []string {"disable" , "--system" , unit }
46
+ args : = []string {"disable" , "--system" , unit }
33
47
if opts .UserMode {
34
48
args [1 ] = "--user"
35
49
}
@@ -44,7 +58,7 @@ func Disable(ctx context.Context, unit string, opts Options) error {
44
58
// manager configuration is reloaded (in a way equivalent to daemon-reload),
45
59
// in order to ensure the changes are taken into account immediately.
46
60
func Enable (ctx context.Context , unit string , opts Options ) error {
47
- var args = []string {"enable" , "--system" , unit }
61
+ args : = []string {"enable" , "--system" , unit }
48
62
if opts .UserMode {
49
63
args [1 ] = "--user"
50
64
}
@@ -57,7 +71,7 @@ func Enable(ctx context.Context, unit string, opts Options) error {
57
71
// Returns true if the unit is active, false if inactive or failed.
58
72
// Also returns false in an error case.
59
73
func IsActive (ctx context.Context , unit string , opts Options ) (bool , error ) {
60
- var args = []string {"is-active" , "--system" , unit }
74
+ args : = []string {"is-active" , "--system" , unit }
61
75
if opts .UserMode {
62
76
args [1 ] = "--user"
63
77
}
@@ -87,7 +101,7 @@ func IsActive(ctx context.Context, unit string, opts Options) (bool, error) {
87
101
// See https://www.freedesktop.org/software/systemd/man/systemctl.html#is-enabled%20UNIT%E2%80%A6
88
102
// for more information
89
103
func IsEnabled (ctx context.Context , unit string , opts Options ) (bool , error ) {
90
- var args = []string {"is-enabled" , "--system" , unit }
104
+ args : = []string {"is-enabled" , "--system" , unit }
91
105
if opts .UserMode {
92
106
args [1 ] = "--user"
93
107
}
@@ -127,7 +141,7 @@ func IsEnabled(ctx context.Context, unit string, opts Options) (bool, error) {
127
141
128
142
// Check whether any of the specified units are in a "failed" state.
129
143
func IsFailed (ctx context.Context , unit string , opts Options ) (bool , error ) {
130
- var args = []string {"is-failed" , "--system" , unit }
144
+ args : = []string {"is-failed" , "--system" , unit }
131
145
if opts .UserMode {
132
146
args [1 ] = "--user"
133
147
}
@@ -149,7 +163,7 @@ func IsFailed(ctx context.Context, unit string, opts Options) (bool, error) {
149
163
// continue masking anyway. Calling Mask on a non-existing masked unit does not
150
164
// return an error. Similarly, see Unmask.
151
165
func Mask (ctx context.Context , unit string , opts Options ) error {
152
- var args = []string {"mask" , "--system" , unit }
166
+ args : = []string {"mask" , "--system" , unit }
153
167
if opts .UserMode {
154
168
args [1 ] = "--user"
155
169
}
@@ -160,7 +174,7 @@ func Mask(ctx context.Context, unit string, opts Options) error {
160
174
// Stop and then start one or more units specified on the command line.
161
175
// If the units are not running yet, they will be started.
162
176
func Restart (ctx context.Context , unit string , opts Options ) error {
163
- var args = []string {"restart" , "--system" , unit }
177
+ args : = []string {"restart" , "--system" , unit }
164
178
if opts .UserMode {
165
179
args [1 ] = "--user"
166
180
}
@@ -171,7 +185,7 @@ func Restart(ctx context.Context, unit string, opts Options) error {
171
185
// Show a selected property of a unit. Accepted properties are predefined in the
172
186
// properties subpackage to guarantee properties are valid and assist code-completion.
173
187
func Show (ctx context.Context , unit string , property properties.Property , opts Options ) (string , error ) {
174
- var args = []string {"show" , "--system" , unit , "--property" , string (property )}
188
+ args : = []string {"show" , "--system" , unit , "--property" , string (property )}
175
189
if opts .UserMode {
176
190
args [1 ] = "--user"
177
191
}
@@ -183,7 +197,7 @@ func Show(ctx context.Context, unit string, property properties.Property, opts O
183
197
184
198
// Start (activate) a given unit
185
199
func Start (ctx context.Context , unit string , opts Options ) error {
186
- var args = []string {"start" , "--system" , unit }
200
+ args : = []string {"start" , "--system" , unit }
187
201
if opts .UserMode {
188
202
args [1 ] = "--user"
189
203
}
@@ -197,7 +211,7 @@ func Start(ctx context.Context, unit string, opts Options) error {
197
211
// Generally, it makes more sense to programatically retrieve the properties
198
212
// using Show, but this command is provided for the sake of completeness
199
213
func Status (ctx context.Context , unit string , opts Options ) (string , error ) {
200
- var args = []string {"status" , "--system" , unit }
214
+ args : = []string {"status" , "--system" , unit }
201
215
if opts .UserMode {
202
216
args [1 ] = "--user"
203
217
}
@@ -207,7 +221,7 @@ func Status(ctx context.Context, unit string, opts Options) (string, error) {
207
221
208
222
// Stop (deactivate) a given unit
209
223
func Stop (ctx context.Context , unit string , opts Options ) error {
210
- var args = []string {"stop" , "--system" , unit }
224
+ args : = []string {"stop" , "--system" , unit }
211
225
if opts .UserMode {
212
226
args [1 ] = "--user"
213
227
}
@@ -223,7 +237,7 @@ func Stop(ctx context.Context, unit string, opts Options) error {
223
237
// If the unit doesn't exist but it's masked anyway, no error will be
224
238
// returned. Gross, I know. Take it up with Poettering.
225
239
func Unmask (ctx context.Context , unit string , opts Options ) error {
226
- var args = []string {"unmask" , "--system" , unit }
240
+ args : = []string {"unmask" , "--system" , unit }
227
241
if opts .UserMode {
228
242
args [1 ] = "--user"
229
243
}
0 commit comments