diff options
| author | xengineering <me@xengineering.eu> | 2026-03-21 17:02:00 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-03-23 16:55:47 +0100 |
| commit | c68b6988d6a6e18efc73d2a979ab427c20ef2108 (patch) | |
| tree | 85fc8d7d8265046c48c53c38fe118b59124a2491 | |
| parent | c47c0736bceff60de31c0afc7005c51c5bf1daa6 (diff) | |
| download | sia-server-c68b6988d6a6e18efc73d2a979ab427c20ef2108.tar sia-server-c68b6988d6a6e18efc73d2a979ab427c20ef2108.tar.zst sia-server-c68b6988d6a6e18efc73d2a979ab427c20ef2108.zip | |
tools: websocket: Add wait for CTRL-C
Now the connection is immediately established but just closed on SIGTERM
and SIGINT.
This allows to keep the connection for some time and lets the user
decide when to stop.
| -rw-r--r-- | tools/websocket.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/websocket.go b/tools/websocket.go index 575bcd5..fc76d56 100644 --- a/tools/websocket.go +++ b/tools/websocket.go @@ -13,6 +13,7 @@ import ( "net/url" "os" "os/signal" + "syscall" "github.com/gorilla/websocket" ) @@ -31,6 +32,8 @@ func main() { log.Fatal(err) } defer c.Close() + + Await(syscall.SIGTERM, syscall.SIGINT) } func getURL() url.URL { @@ -45,3 +48,12 @@ func getURL() url.URL { return *maybeURL } + +func Await(signals ...os.Signal) { + listener := make(chan os.Signal, 1) + signal.Notify(listener, signals...) + defer signal.Stop(listener) + + sig := <-listener + log.Printf("Received OS signal '%v'\n", sig) +} |
