Skip to content

Commit

Permalink
add doc for idle server auto shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
balki committed Sep 12, 2023
1 parent e95d2d0 commit 0693a56
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Create http server listening on unix sockets or systemd socket activated fds
Create http server listening on unix sockets and systemd socket activated fds

## Quick Usage

Expand Down Expand Up @@ -44,19 +44,34 @@ Examples:

### TCP port

If the address is a number less than 65536, it is assumed as a port and passed as `http.ListenAndServe(":<port>",...)`

Anything else is directly passed to `http.ListenAndServe` as well. Below examples should work
If the address is a number less than 65536, it is assumed as a port and passed
as `http.ListenAndServe(":<port>",...)` Anything else is directly passed to
`http.ListenAndServe` as well. Below examples should work

:http
:8888
127.0.0.1:8080

## Idle server auto shutdown

When using systemd socket activation, idle servers can be shut down to save on
resources. They will be restarted with socket activation when new request
arrives. Quick example for the case. (Error checking skipped for brevity)

```go
addrType, httpServer, done, _ := anyhttp.Serve(addr, idle.WrapHandler(nil))
if addrType == anyhttp.SystemdFD {
idle.Wait(30 * time.Minute)
httpServer.Shutdown(context.TODO())
}
<-done
```

## Documentation

https://pkg.go.dev/go.balki.me/anyhttp

### Related links

* https://gist.github.com/teknoraver/5ffacb8757330715bcbcc90e6d46ac74#file-unixhttpd-go
* https://github.com/coreos/go-systemd/tree/main/activation
* https://github.com/coreos/go-systemd/tree/main/activation

0 comments on commit 0693a56

Please sign in to comment.