forked from OKEAMAH/animated-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystemd.go
More file actions
26 lines (21 loc) · 737 Bytes
/
systemd.go
File metadata and controls
26 lines (21 loc) · 737 Bytes
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
package node
import (
"fmt"
"net"
"github.com/coreos/go-systemd/activation"
)
func getSDListeners() ([]net.Listener, error) {
// We use systemd socket activation for (almost) zero downtime deployment -
// systemd will keep the socket open even while we restart the process
// (plus, it allows us to bind to unprivileged ports without extra capabilities).
//
// Read more: https://vincent.bernat.ch/en/blog/2018-systemd-golang-socket-activation
listeners, err := activation.Listeners()
if err != nil {
return nil, fmt.Errorf("cannot retrieve listeners: %v", err)
}
if len(listeners) != 1 {
return nil, fmt.Errorf("unexpected number of sockets passed by systemd (%d != 1)", len(listeners))
}
return listeners, nil
}