-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemd.go
67 lines (58 loc) · 1.14 KB
/
systemd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (C) 2021-2023 David Sugar, Tycho Softworks
// This code is licensed under MIT license
//go:build linux
package service
import (
"fmt"
"github.com/coreos/go-systemd/daemon"
)
var stopping = false
func Reload(args ...interface{}) error {
msg := fmt.Sprint(args...)
if len(msg) > 0 {
Info(msg)
}
if stopping {
return nil
}
_, err := daemon.SdNotify(false, daemon.SdNotifyReloading)
return err
}
func Live(args ...interface{}) error {
if stopping {
return nil
}
msg := fmt.Sprint(args...)
if len(msg) > 0 {
Info(msg)
}
_, err := daemon.SdNotify(false, daemon.SdNotifyReady)
return err
}
func Status(status string) error {
if stopping {
return nil
}
msg := fmt.Sprintf("%s\nSTATUS=%s\n", daemon.SdNotifyReady, status)
_, err := daemon.SdNotify(false, msg)
return err
}
func Stop(args ...interface{}) error {
if stopping {
return nil
}
stopping = true
_, err := daemon.SdNotify(true, daemon.SdNotifyStopping)
msg := fmt.Sprint(args...)
if len(msg) > 0 {
Info(msg)
}
return err
}
func Watchdog() error {
if stopping {
return nil
}
_, err := daemon.SdNotify(false, daemon.SdNotifyWatchdog)
return err
}