summaryrefslogtreecommitdiff
path: root/internal/cli/serve
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2023-08-06 22:57:16 +0200
committerValery Piashchynski <[email protected]>2023-08-06 22:57:16 +0200
commitd5886b45fa3d8e65f6217f8f37fe848d6355c851 (patch)
tree6634496990556b9f1cf86a6e652d559632095299 /internal/cli/serve
parent3bf88db8a91fcb79fb46c80abdbf55ab8d4a9f8f (diff)
feature: sd_notify support
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'internal/cli/serve')
-rw-r--r--internal/cli/serve/command.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/internal/cli/serve/command.go b/internal/cli/serve/command.go
index 2bdb7565..21454933 100644
--- a/internal/cli/serve/command.go
+++ b/internal/cli/serve/command.go
@@ -9,6 +9,7 @@ import (
"github.com/roadrunner-server/endure/v2"
"github.com/roadrunner-server/roadrunner/v2023/container"
"github.com/roadrunner-server/roadrunner/v2023/internal/meta"
+ "github.com/roadrunner-server/roadrunner/v2023/internal/sdnotify"
configImpl "github.com/roadrunner-server/config/v4"
"github.com/roadrunner-server/errors"
@@ -54,7 +55,13 @@ func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Comman
}
// create endure container
- cont := endure.New(containerCfg.LogLevel, endureOptions...)
+ ll, err := container.ParseLogLevel(containerCfg.LogLevel)
+ if err != nil {
+ if !*silent {
+ fmt.Printf("[WARN] Failed to parse log level, using default (error): %s\n", err)
+ }
+ }
+ cont := endure.New(ll, endureOptions...)
// register plugins
err = cont.RegisterAll(append(container.Plugins(), cfg)...)
@@ -75,7 +82,7 @@ func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Comman
}
oss, stop := make(chan os.Signal, 5), make(chan struct{}, 1) //nolint:gomnd
- signal.Notify(oss, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
+ signal.Notify(oss, os.Interrupt, syscall.SIGTERM, syscall.SIGINT, syscall.SIGABRT)
go func() {
// first catch - stop the container
@@ -83,8 +90,10 @@ func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Comman
// send signal to stop execution
stop <- struct{}{}
- // after first hit we are waiting for the second
- // second catch - exit from the process
+ // notify about stopping
+ _, _ = sdnotify.SdNotify(sdnotify.Stopping)
+
+ // after first hit we are waiting for the second catch - exit from the process
<-oss
fmt.Println("exit forced")
os.Exit(1)
@@ -94,6 +103,26 @@ func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Comman
fmt.Printf("[INFO] RoadRunner server started; version: %s, buildtime: %s\n", meta.Version(), meta.BuildTime())
}
+ // at this moment, we're almost sure that the container is running (almost- because we don't know if the plugins won't report an error on the next step)
+ notified, err := sdnotify.SdNotify(sdnotify.Ready)
+ if err != nil {
+ if !*silent {
+ fmt.Printf("[WARN] sdnotify: %s\n", err)
+ }
+ }
+
+ if !*silent {
+ if notified {
+ fmt.Println("[INFO] sdnotify: notified")
+ // if notified -> notify about stop
+ defer func() {
+ _, _ = sdnotify.SdNotify(sdnotify.Stopping)
+ }()
+ } else {
+ fmt.Println("[INFO] sdnotify: not notified")
+ }
+ }
+
for {
select {
case e := <-errCh: