Skip to content

Commit 0b60093

Browse files
author
Brandon Philips
committed
fix(examples): convert httpserver to Listeners
move to the activation.Listeners API and cleanup the README
1 parent 4a3b33e commit 0b60093

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
Example of using socket activation with systemd to serve a simple HTTP server on http://127.0.0.1:8076
1+
## socket activated http server
2+
3+
This is a simple example of using socket activation with systemd to serve a
4+
simple HTTP server on http://127.0.0.1:8076
5+
6+
To try it out `go get` the httpserver and run it under the systemd-activate helper
7+
8+
```
9+
export GOPATH=`pwd`
10+
go get github.com/coreos/go-systemd/examples/activation/httpserver
11+
sudo /usr/lib/systemd/systemd-activate -l 127.0.0.1:8076 ./bin/httpserver
12+
```
13+
14+
Then curl the URL and you will notice that it starts up:
15+
16+
```
17+
curl 127.0.0.1:8076
18+
hello socket activated world!
19+
```

examples/activation/httpserver/httpserver.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"io"
5-
"net"
65
"net/http"
76

87
"github.com/coreos/go-systemd/activation"
@@ -13,17 +12,15 @@ func HelloServer(w http.ResponseWriter, req *http.Request) {
1312
}
1413

1514
func main() {
16-
files := activation.Files(true)
17-
18-
if len(files) != 1 {
19-
panic("Unexpected number of socket activation fds")
20-
}
21-
22-
l, err := net.FileListener(files[0])
15+
listeners, err := activation.Listeners(true)
2316
if err != nil {
2417
panic(err)
2518
}
2619

20+
if len(listeners) != 1 {
21+
panic("Unexpected number of socket activation fds")
22+
}
23+
2724
http.HandleFunc("/", HelloServer)
28-
http.Serve(l, nil)
25+
http.Serve(listeners[0], nil)
2926
}

0 commit comments

Comments
 (0)