...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package main
20
21 import (
22 "fmt"
23 "os"
24
25 "github.com/coreos/go-systemd/v22/activation"
26 )
27
28 func fixListenPid() {
29 if os.Getenv("FIX_LISTEN_PID") != "" {
30
31
32
33 os.Setenv("LISTEN_PID", fmt.Sprintf("%d", os.Getpid()))
34 }
35 }
36
37 func main() {
38 fixListenPid()
39
40 files := activation.Files(false)
41
42 if len(files) == 0 {
43 panic("No files")
44 }
45
46 if os.Getenv("LISTEN_PID") == "" || os.Getenv("LISTEN_FDS") == "" || os.Getenv("LISTEN_FDNAMES") == "" {
47 panic("Should not unset envs")
48 }
49
50 files = activation.Files(true)
51
52 if os.Getenv("LISTEN_PID") != "" || os.Getenv("LISTEN_FDS") != "" || os.Getenv("LISTEN_FDNAMES") != "" {
53 panic("Can not unset envs")
54 }
55
56
57 files[0].Write([]byte("Hello world: " + files[0].Name()))
58 files[1].Write([]byte("Goodbye world: " + files[1].Name()))
59
60 return
61 }
62
View as plain text