diff options
| author | Shulhan <ms@kilabit.info> | 2026-02-02 21:19:05 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-02-02 21:19:12 +0700 |
| commit | a6e71dc31738c4a003dae9f9547348968beeefc4 (patch) | |
| tree | cf9690d67f9f5eacab8e2b2d1ec7e6109d77e06f /internal/cmd | |
| parent | 1f4ead1b7488cc17d735d228e151d42c1ab7d10f (diff) | |
| download | awwan-a6e71dc31738c4a003dae9f9547348968beeefc4.tar.xz | |
internal/cmd/www-awwan: implement socket based activation using systemd
This allow us to run www-awwan only when its activated in the local
environment.
Diffstat (limited to 'internal/cmd')
| -rw-r--r-- | internal/cmd/www-awwan/main.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/cmd/www-awwan/main.go b/internal/cmd/www-awwan/main.go index 8e11601..87b6d6f 100644 --- a/internal/cmd/www-awwan/main.go +++ b/internal/cmd/www-awwan/main.go @@ -16,6 +16,7 @@ import ( "git.sr.ht/~shulhan/ciigo" "git.sr.ht/~shulhan/pakakeh.go/lib/memfs" + "git.sr.ht/~shulhan/pakakeh.go/lib/systemd" "git.sr.ht/~shulhan/awwan/internal" ) @@ -74,6 +75,22 @@ func main() { IsDevelopment: *flagDev, } + listeners, err := systemd.Listeners(true) + if err != nil { + log.Fatal(err) + } + if len(listeners) > 1 { + log.Fatal(`too many listeners received for activation`) + } + if len(listeners) == 1 { + optsServe.Listener = listeners[0] + gotAddr := optsServe.Listener.Addr().String() + if gotAddr != optsServe.Address { + log.Fatalf(`invalid Listener address, got %s, want %s`, + gotAddr, optsServe.Address) + } + } + err = ciigo.Serve(optsServe) if err != nil { log.Fatal(err) |
