File tree Expand file tree Collapse file tree 2 files changed +25
-10
lines changed
examples/activation/httpserver Expand file tree Collapse file tree 2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package main
22
33import (
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
1514func 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}
You can’t perform that action at this time.
0 commit comments