summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.pid2
-rw-r--r--internal/cli/root.go5
-rw-r--r--internal/cli/serve/command.go4
-rw-r--r--internal/cli/stop/command.go12
-rw-r--r--internal/cli/stop/command_test.go4
5 files changed, 21 insertions, 6 deletions
diff --git a/.pid b/.pid
index a1fe95fb..9af205b0 100644
--- a/.pid
+++ b/.pid
@@ -1 +1 @@
-100144 \ No newline at end of file
+181292 \ No newline at end of file
diff --git a/internal/cli/root.go b/internal/cli/root.go
index 0ea12814..1af7ef41 100644
--- a/internal/cli/root.go
+++ b/internal/cli/root.go
@@ -31,6 +31,8 @@ func NewCommand(cmdName string) *cobra.Command { //nolint:funlen,gocognit
cfgFile := toPtr("")
// pidfile path
pidFile := toPtr(false)
+ // force stop RR
+ forceStop := toPtr(false)
// override config values
override := &[]string{}
// do not print startup message
@@ -113,6 +115,7 @@ func NewCommand(cmdName string) *cobra.Command { //nolint:funlen,gocognit
f := cmd.PersistentFlags()
+ f.BoolVarP(forceStop, "force", "f", false, "force stop")
f.BoolVarP(pidFile, "pid", "p", false, "create a .pid file")
f.StringVarP(cfgFile, "config", "c", ".rr.yaml", "config file")
f.StringVarP(&workDir, "WorkDir", "w", "", "working directory")
@@ -125,7 +128,7 @@ func NewCommand(cmdName string) *cobra.Command { //nolint:funlen,gocognit
workers.NewCommand(cfgFile, override),
reset.NewCommand(cfgFile, override, silent),
serve.NewCommand(override, cfgFile, silent),
- stop.NewCommand(silent),
+ stop.NewCommand(silent, forceStop),
)
return cmd
diff --git a/internal/cli/serve/command.go b/internal/cli/serve/command.go
index 6cbdef44..a85beb89 100644
--- a/internal/cli/serve/command.go
+++ b/internal/cli/serve/command.go
@@ -5,6 +5,7 @@ import (
"os"
"os/signal"
"syscall"
+ "time"
"github.com/roadrunner-server/roadrunner/v2/internal/container"
"github.com/roadrunner-server/roadrunner/v2/internal/meta"
@@ -73,7 +74,7 @@ func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Comman
return errors.E(op, err)
}
- oss, stop := make(chan os.Signal, 2), make(chan struct{}, 1) //nolint:gomnd
+ oss, stop := make(chan os.Signal, 5), make(chan struct{}, 1) //nolint:gomnd
signal.Notify(oss, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
go func() {
@@ -100,6 +101,7 @@ func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Comman
case <-stop: // stop the container after first signal
fmt.Printf("stop signal received, grace timeout is: %0.f seconds\n", containerCfg.GracePeriod.Seconds())
+ time.Sleep(time.Second * 100)
if err = endureContainer.Stop(); err != nil {
return fmt.Errorf("error: %w", err)
}
diff --git a/internal/cli/stop/command.go b/internal/cli/stop/command.go
index 8b4b589f..533f11d6 100644
--- a/internal/cli/stop/command.go
+++ b/internal/cli/stop/command.go
@@ -5,6 +5,7 @@ import (
"os"
"strconv"
"syscall"
+ "time"
"github.com/roadrunner-server/errors"
"github.com/spf13/cobra"
@@ -16,7 +17,7 @@ const (
)
// NewCommand creates `serve` command.
-func NewCommand(silent *bool) *cobra.Command {
+func NewCommand(silent *bool, force *bool) *cobra.Command {
return &cobra.Command{
Use: "stop",
Short: "Stop RoadRunner server",
@@ -47,6 +48,15 @@ func NewCommand(silent *bool) *cobra.Command {
return errors.E(op, err)
}
+ if *force {
+ // RR may lost the signal if we immediately send it
+ time.Sleep(time.Second)
+ err = process.Signal(syscall.SIGTERM)
+ if err != nil {
+ return errors.E(op, err)
+ }
+ }
+
return nil
},
}
diff --git a/internal/cli/stop/command_test.go b/internal/cli/stop/command_test.go
index 8bbb29ea..13f01bed 100644
--- a/internal/cli/stop/command_test.go
+++ b/internal/cli/stop/command_test.go
@@ -9,14 +9,14 @@ import (
)
func TestCommandProperties(t *testing.T) {
- cmd := stop.NewCommand(toPtr(false))
+ cmd := stop.NewCommand(toPtr(false), toPtr(false))
assert.Equal(t, "stop", cmd.Use)
assert.NotNil(t, cmd.RunE)
}
func TestCommandTrue(t *testing.T) {
- cmd := stop.NewCommand(toPtr(true))
+ cmd := stop.NewCommand(toPtr(true), toPtr(true))
assert.Equal(t, "stop", cmd.Use)
assert.NotNil(t, cmd.RunE)