diff --git a/README.md b/README.md index 35950d4..8e15909 100644 --- a/README.md +++ b/README.md @@ -17,56 +17,57 @@ Just replace `http.ListenAndServe` with `anyhttp.ListenAndServe`. Syntax - unix/ + unix?path=&mode=&remove_existing= Examples - unix/relative/path.sock - unix//var/run/app/absolutepath.sock + unix?path=relative/path.sock + unix?path=/var/run/app/absolutepath.sock + unix?path=/run/app.sock&mode=600&remove_existing=no + +| option | description | default | +|-----------------|------------------------------------------------|----------| +| path | path to unix socket | Required | +| mode | socket file mode | 666 | +| remove_existing | Whether to remove existing socket file or fail | true | ### Systemd Socket activated fd: Syntax - sysd/fdidx/ - sysd/fdname/ + sysd?idx=&name=&check_pid=&unset_env=&idle_timeout= + +Only one of `idx` or `name` has to be set Examples: # First (or only) socket fd passed to app - sysd/fdidx/0 + sysd?idx=0 # Socket with FileDescriptorName - sysd/fdname/myapp + sysd?name=myapp - # Using default name - sysd/fdname/myapp.socket + # Using default name and auto shutdown if no requests received in last 30 minutes + sysd?name=myapp.socket&idle_timeout=30m -### TCP port +| option | description | default | +|--------------|--------------------------------------------------------------------------------------------|------------------| +| name | Name configured via FileDescriptorName or socket file name | Required | +| idx | FD Index. Actual fd num will be 3 + idx | Required | +| idle_timeout | time to wait before shutdown. [syntax][0] | no auto shutdown | +| check_pid | Check process PID matches LISTEN_PID | true | +| unset_env | Unsets the LISTEN\* environment variables, so they don't get passed to any child processes | true | -If the address is a number less than 65536, it is assumed as a port and passed -as `http.ListenAndServe(":",...)` Anything else is directly passed to -`http.ListenAndServe` as well. Below examples should work +### TCP + +If the address is not one of above, it is assumed to be tcp and passed to `http.ListenAndServe`. + +Examples: :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 @@ -75,3 +76,5 @@ https://pkg.go.dev/go.balki.me/anyhttp * https://gist.github.com/teknoraver/5ffacb8757330715bcbcc90e6d46ac74#file-unixhttpd-go * https://github.com/coreos/go-systemd/tree/main/activation + +[0]: https://pkg.go.dev/time#ParseDuration