diff options
| author | Shulhan <ms@kilabit.info> | 2026-02-12 00:21:57 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-02-12 01:29:15 +0700 |
| commit | 1aa46846bc1bfe64c1608e8a536b1732cc3d3b1a (patch) | |
| tree | ee63e3e4136735d0394c7bfd76d5ecbf9759d0c6 | |
| parent | ff5a7ecdb8aa0ccfe4bd4f71648e7254e470c930 (diff) | |
| download | awwan-1aa46846bc1bfe64c1608e8a536b1732cc3d3b1a.tar.xz | |
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.
| -rw-r--r-- | CHANGELOG.adoc | 5 | ||||
| -rw-r--r-- | 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 <start> until line <end>. - serve [-address] <workspace> + serve [-address <string>] [-shutdown-idle <duration>] <workspace> Run the web-user interface (WUI) using <workspace> 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. |
