Skip to content

Commit b581659

Browse files
authored
feat: enhance RestartService function to support forced restarts (#70)
1 parent 6d3149c commit b581659

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

utils/systemctl/systemctl.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func StopService(name string, wait ...time.Duration) error {
298298
return nil
299299
}
300300

301-
func RestartService(name string, wait ...time.Duration) error {
301+
func RestartService(name string, force bool, wait ...time.Duration) error {
302302
timeout := 30 * time.Second
303303
if len(wait) > 0 {
304304
timeout = wait[0]
@@ -316,9 +316,17 @@ func RestartService(name string, wait ...time.Duration) error {
316316
defer conn.Close()
317317

318318
ch := make(chan string)
319-
_, err = conn.ReloadOrRestartUnitContext(ctx, name, "replace", ch)
320-
if err != nil {
321-
return err
319+
320+
if force {
321+
_, err = conn.RestartUnitContext(ctx, name, "replace", ch)
322+
if err != nil {
323+
return err
324+
}
325+
} else {
326+
_, err = conn.ReloadOrRestartUnitContext(ctx, name, "replace", ch)
327+
if err != nil {
328+
return err
329+
}
322330
}
323331

324332
result := <-ch

0 commit comments

Comments
 (0)