From 1aa46846bc1bfe64c1608e8a536b1732cc3d3b1a Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 12 Feb 2026 00:21:57 +0700 Subject: cmd/awwan: add option to auto shutdown idle serve The `-shutdown-idle` option set the duration when the "serve" command will stop accepting new connections and shutting down the HTTP server. --- CHANGELOG.adoc | 5 +++++ cmd/awwan/main.go | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1a0cf80..7cb4910 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -29,6 +29,11 @@ In case we needs to add another parameter, which will do later, the argument will be too long. Using parameters is acceptable only for 2 to 3 arguments. +**🌱 cmd/awwan: add option to auto shutdown idle serve** + +The `-shutdown-idle` option set the duration when the "serve" command +will stop accepting new connections and shutting down the HTTP server. + [#v0_13_1] == awwan v0.13.1 (2026-02-09) diff --git a/cmd/awwan/main.go b/cmd/awwan/main.go index da0429c..019e3c1 100644 --- a/cmd/awwan/main.go +++ b/cmd/awwan/main.go @@ -13,6 +13,7 @@ import ( "net" "os" "strings" + "time" "git.sr.ht/~shulhan/awwan" "git.sr.ht/~shulhan/pakakeh.go/lib/systemd" @@ -81,7 +82,7 @@ command = "decrypt" / "encrypt" / "help" / "local" / "play" / "serve" / "version Execute the script in the remote server from line until line . - serve [-address] + serve [-address ] [-shutdown-idle ] Run the web-user interface (WUI) using directory as base directory. The "-address" option define the HTTP server address to @@ -127,14 +128,27 @@ Run the web-user interface using the current directory as workspace, func main() { var logp = `awwan` var serveOpts = awwan.ServeOptions{} + var shutdownIdleDuration string flag.StringVar(&serveOpts.Address, `address`, awwan.DefListenAddress, `HTTP server address to serve web user interface.`) + + flag.StringVar(&shutdownIdleDuration, `shutdown-idle`, ``, + `Set the duration for automatic shutdown on "serve" command.`) + flag.BoolVar(&serveOpts.IsDevelopment, `dev`, false, `Turn on development mode.`) flag.Parse() + var err error + if shutdownIdleDuration != `` { + serveOpts.ShutdownIdleDuration, err = time.ParseDuration(shutdownIdleDuration) + if err != nil { + log.Fatalf(`invalid shutdown-idle %s: %s`, shutdownIdleDuration, err) + } + } + if flag.NArg() <= 0 { usage() os.Exit(1) @@ -146,7 +160,6 @@ func main() { req *awwan.ExecRequest baseDir string file string - err error ) // Check for valid command and flags. -- cgit v1.3