diff options
| author | Nick Khyl <nickk@tailscale.com> | 2024-12-05 13:16:48 -0600 |
|---|---|---|
| committer | Nick Khyl <nickk@tailscale.com> | 2024-12-05 13:16:48 -0600 |
| commit | 0267fe83b200f1702a2fa0a395442c02a053fadb (patch) | |
| tree | 63654c55225eeb834de59a5a0bc8d19033c6145b /util/systemd | |
| parent | 87546a5edf6b6503a87eeb2d666baba57398a066 (diff) | |
| download | tailscale-1.78.0.tar.xz tailscale-1.78.0.zip | |
VERSION.txt: this is v1.78.0v1.78.0
Signed-off-by: Nick Khyl <nickk@tailscale.com>
Diffstat (limited to 'util/systemd')
| -rw-r--r-- | util/systemd/doc.go | 26 | ||||
| -rw-r--r-- | util/systemd/systemd_linux.go | 154 | ||||
| -rw-r--r-- | util/systemd/systemd_nonlinux.go | 18 |
3 files changed, 99 insertions, 99 deletions
diff --git a/util/systemd/doc.go b/util/systemd/doc.go index 0c28e1823..296f74e9d 100644 --- a/util/systemd/doc.go +++ b/util/systemd/doc.go @@ -1,13 +1,13 @@ -// Copyright (c) Tailscale Inc & AUTHORS -// SPDX-License-Identifier: BSD-3-Clause - -/* -Package systemd contains a minimal wrapper around systemd-notify to enable -applications to signal readiness and status to systemd. - -This package will only have effect on Linux systems running Tailscale in a -systemd unit with the Type=notify flag set. On other operating systems (or -when running in a Linux distro without being run from inside systemd) this -package will become a no-op. -*/ -package systemd +// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+/*
+Package systemd contains a minimal wrapper around systemd-notify to enable
+applications to signal readiness and status to systemd.
+
+This package will only have effect on Linux systems running Tailscale in a
+systemd unit with the Type=notify flag set. On other operating systems (or
+when running in a Linux distro without being run from inside systemd) this
+package will become a no-op.
+*/
+package systemd
diff --git a/util/systemd/systemd_linux.go b/util/systemd/systemd_linux.go index 909cfcb20..34d6daff3 100644 --- a/util/systemd/systemd_linux.go +++ b/util/systemd/systemd_linux.go @@ -1,77 +1,77 @@ -// Copyright (c) Tailscale Inc & AUTHORS -// SPDX-License-Identifier: BSD-3-Clause - -//go:build linux - -package systemd - -import ( - "errors" - "log" - "os" - "sync" - - "github.com/mdlayher/sdnotify" -) - -var getNotifyOnce struct { - sync.Once - v *sdnotify.Notifier -} - -type logOnce struct { - sync.Once -} - -func (l *logOnce) logf(format string, args ...any) { - l.Once.Do(func() { - log.Printf(format, args...) - }) -} - -var ( - readyOnce = &logOnce{} - statusOnce = &logOnce{} -) - -func notifier() *sdnotify.Notifier { - getNotifyOnce.Do(func() { - var err error - getNotifyOnce.v, err = sdnotify.New() - // Not exist means probably not running under systemd, so don't log. - if err != nil && !errors.Is(err, os.ErrNotExist) { - log.Printf("systemd: systemd-notifier error: %v", err) - } - }) - return getNotifyOnce.v -} - -// Ready signals readiness to systemd. This will unblock service dependents from starting. -func Ready() { - err := notifier().Notify(sdnotify.Ready) - if err != nil { - readyOnce.logf("systemd: error notifying: %v", err) - } -} - -// Status sends a single line status update to systemd so that information shows up -// in systemctl output. For example: -// -// $ systemctl status tailscale -// ● tailscale.service - Tailscale client daemon -// Loaded: loaded (/nix/store/qc312qcy907wz80fqrgbbm8a9djafmlg-unit-tailscale.service/tailscale.service; enabled; vendor preset: enabled) -// Active: active (running) since Tue 2020-11-24 17:54:07 EST; 13h ago -// Main PID: 26741 (.tailscaled-wra) -// Status: "Connected; user@host.domain.tld; 100.101.102.103" -// IP: 0B in, 0B out -// Tasks: 22 (limit: 4915) -// Memory: 30.9M -// CPU: 2min 38.469s -// CGroup: /system.slice/tailscale.service -// └─26741 /nix/store/sv6cj4mw2jajm9xkbwj07k29dj30lh0n-tailscale-date.20200727/bin/tailscaled --port 41641 -func Status(format string, args ...any) { - err := notifier().Notify(sdnotify.Statusf(format, args...)) - if err != nil { - statusOnce.logf("systemd: error notifying: %v", err) - } -} +// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+//go:build linux
+
+package systemd
+
+import (
+ "errors"
+ "log"
+ "os"
+ "sync"
+
+ "github.com/mdlayher/sdnotify"
+)
+
+var getNotifyOnce struct {
+ sync.Once
+ v *sdnotify.Notifier
+}
+
+type logOnce struct {
+ sync.Once
+}
+
+func (l *logOnce) logf(format string, args ...any) {
+ l.Once.Do(func() {
+ log.Printf(format, args...)
+ })
+}
+
+var (
+ readyOnce = &logOnce{}
+ statusOnce = &logOnce{}
+)
+
+func notifier() *sdnotify.Notifier {
+ getNotifyOnce.Do(func() {
+ var err error
+ getNotifyOnce.v, err = sdnotify.New()
+ // Not exist means probably not running under systemd, so don't log.
+ if err != nil && !errors.Is(err, os.ErrNotExist) {
+ log.Printf("systemd: systemd-notifier error: %v", err)
+ }
+ })
+ return getNotifyOnce.v
+}
+
+// Ready signals readiness to systemd. This will unblock service dependents from starting.
+func Ready() {
+ err := notifier().Notify(sdnotify.Ready)
+ if err != nil {
+ readyOnce.logf("systemd: error notifying: %v", err)
+ }
+}
+
+// Status sends a single line status update to systemd so that information shows up
+// in systemctl output. For example:
+//
+// $ systemctl status tailscale
+// ● tailscale.service - Tailscale client daemon
+// Loaded: loaded (/nix/store/qc312qcy907wz80fqrgbbm8a9djafmlg-unit-tailscale.service/tailscale.service; enabled; vendor preset: enabled)
+// Active: active (running) since Tue 2020-11-24 17:54:07 EST; 13h ago
+// Main PID: 26741 (.tailscaled-wra)
+// Status: "Connected; user@host.domain.tld; 100.101.102.103"
+// IP: 0B in, 0B out
+// Tasks: 22 (limit: 4915)
+// Memory: 30.9M
+// CPU: 2min 38.469s
+// CGroup: /system.slice/tailscale.service
+// └─26741 /nix/store/sv6cj4mw2jajm9xkbwj07k29dj30lh0n-tailscale-date.20200727/bin/tailscaled --port 41641
+func Status(format string, args ...any) {
+ err := notifier().Notify(sdnotify.Statusf(format, args...))
+ if err != nil {
+ statusOnce.logf("systemd: error notifying: %v", err)
+ }
+}
diff --git a/util/systemd/systemd_nonlinux.go b/util/systemd/systemd_nonlinux.go index 36214020c..d8b20665f 100644 --- a/util/systemd/systemd_nonlinux.go +++ b/util/systemd/systemd_nonlinux.go @@ -1,9 +1,9 @@ -// Copyright (c) Tailscale Inc & AUTHORS -// SPDX-License-Identifier: BSD-3-Clause - -//go:build !linux - -package systemd - -func Ready() {} -func Status(string, ...any) {} +// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+//go:build !linux
+
+package systemd
+
+func Ready() {}
+func Status(string, ...any) {}
|
