-
Notifications
You must be signed in to change notification settings - Fork 14
TCM: Add tt tcm status/stop #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
68dc463
to
8f4ff5f
Compare
8f4ff5f
to
c30d7d8
Compare
61141f5
to
3923916
Compare
6a1d18d
to
79fc7fb
Compare
79fc7fb
to
95f40ab
Compare
95f40ab
to
8815ff3
Compare
CHANGELOG.md
Outdated
- `tt aeon connect`: added tests for connect file/app. | ||
- `tt pack `: support `.packignore` file to specify files that should not be included | ||
in package (works the same as `.gitignore`). | ||
- `tt tcm start`: add the tcm command. | ||
- `tt tcm start` OR `tt tcm start --path /path/to/tcm`: added the capability to run TCM in interactive mode. | ||
- `tt tcm start --watchdog`: implemented Watchdog mode for automatic restarting of TCM upon unexpected termination. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not implemented in the PR. Looks like a rebase artifacts or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
CHANGELOG.md
Outdated
- `sslkeyfile` - path to a private SSL key file, | ||
- `sslcertfile` - path to an SSL certificate file, | ||
- `sslcafile` - path to a trusted certificate authorities (CA) file, | ||
- `sslciphers` - colon-separated list of SSL cipher suites the connection. | ||
- `tt play`: support connection to a target instance by `application` name | ||
or `application:instance` name. | ||
- `tt coredump pack`: add options to customize coredump packing: | ||
* `-e (--executable)`: specify Tarantool executable path. | ||
* `-p (--pid)`: specify PID of the dumped process. | ||
* `-t (--time)`: specify time of dump (seconds since the Epoch). | ||
- `-e (--executable)`: specify Tarantool executable path. | ||
- `-p (--pid)`: specify PID of the dumped process. | ||
- `-t (--time)`: specify time of dump (seconds since the Epoch). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add a separate commit with a format update if you want to change a formatting of the whole file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I corrected it, but one line still looks like a new line for some unknown reason.
@TarantoolBot document Title: add the tt tcm status command. Add `tt tcm status` command that displays whether TCM is running in: - watchdog mode (with auto-recovery) - interactive mode Closes #TNTP-1992
8815ff3
to
2c979d4
Compare
cli/cmd/tcm.go
Outdated
tcmPidFile = "tcmPidFile.pid" | ||
watchdogPidFile = "watchdogPidFile.pid" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the suffix since we have a file extension that told us that it is a pid file.
tcmPidFile = "tcmPidFile.pid" | |
watchdogPidFile = "watchdogPidFile.pid" | |
tcmPidFile = "tcm.pid" | |
watchdogPidFile = "watchdog.pid" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// ExistsAndRecord checks if the process with the given pidFileName exists and is alive. | ||
// If it does, returns true, otherwise returns false. | ||
// If something went wrong while trying to read the PID file, returns an error. | ||
func ExistsAndRecord(pidFileName string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a test for the call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/watchdog/watchdog.go
Outdated
// Command for launching and managing the child process. | ||
cmd *exec.Cmd | ||
// Timeout before restarting a failed process. | ||
restartTimeout time.Duration | ||
// Atomic flag for graceful shutdown. | ||
shouldStop atomic.Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a common code style in go. Please fix comments below.
// Command for launching and managing the child process. | |
cmd *exec.Cmd | |
// Timeout before restarting a failed process. | |
restartTimeout time.Duration | |
// Atomic flag for graceful shutdown. | |
shouldStop atomic.Bool | |
// cmd is a command for launching and managing the child process. | |
cmd *exec.Cmd | |
// restartTimeout is a timeout before restarting a failed process. | |
restartTimeout time.Duration | |
// shouldStop is an atomic flag for graceful shutdown. | |
shouldStop atomic.Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/watchdog/watchdog_test.go
Outdated
// TestWatchdog_StartStop tests that the watchdog starts a process, creates a PID | ||
// file, and stops the process when asked to. | ||
func TestWatchdog_StartStop(t *testing.T) { | ||
t.Run("successful start and graceful stop", func(t *testing.T) { | ||
wd := NewWatchdog("test.pid", "wd.pid", 100*time.Millisecond) | ||
|
||
t.Cleanup(func() { | ||
os.Remove("test.pid") | ||
os.Remove("wd.pid") | ||
}) | ||
|
||
// Mock command that will sleep for 1 second. | ||
cmd := exec.Command("sleep", "1") | ||
errChan := make(chan error, 1) | ||
|
||
go func() { | ||
errChan <- wd.Start(cmd.Path, cmd.Args[1:]...) | ||
}() | ||
|
||
// Wait for process to start. | ||
time.Sleep(200 * time.Millisecond) | ||
|
||
// Verify process is running. | ||
wd.cmdMutex.Lock() | ||
require.NotNil(t, wd.cmd) | ||
require.NotNil(t, wd.cmd.Process) | ||
wd.cmdMutex.Unlock() | ||
|
||
// Stop the watchdog. | ||
wd.Stop() | ||
|
||
// Verify no errors. | ||
select { | ||
case err := <-errChan: | ||
require.NoError(t, err) | ||
case <-time.After(500 * time.Millisecond): | ||
t.Fatal("timeout waiting for Start to return") | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, rewrite tests without an additional nested level.
// TestWatchdog_StartStop tests that the watchdog starts a process, creates a PID | |
// file, and stops the process when asked to. | |
func TestWatchdog_StartStop(t *testing.T) { | |
t.Run("successful start and graceful stop", func(t *testing.T) { | |
wd := NewWatchdog("test.pid", "wd.pid", 100*time.Millisecond) | |
t.Cleanup(func() { | |
os.Remove("test.pid") | |
os.Remove("wd.pid") | |
}) | |
// Mock command that will sleep for 1 second. | |
cmd := exec.Command("sleep", "1") | |
errChan := make(chan error, 1) | |
go func() { | |
errChan <- wd.Start(cmd.Path, cmd.Args[1:]...) | |
}() | |
// Wait for process to start. | |
time.Sleep(200 * time.Millisecond) | |
// Verify process is running. | |
wd.cmdMutex.Lock() | |
require.NotNil(t, wd.cmd) | |
require.NotNil(t, wd.cmd.Process) | |
wd.cmdMutex.Unlock() | |
// Stop the watchdog. | |
wd.Stop() | |
// Verify no errors. | |
select { | |
case err := <-errChan: | |
require.NoError(t, err) | |
case <-time.After(500 * time.Millisecond): | |
t.Fatal("timeout waiting for Start to return") | |
} | |
}) | |
// TestWatchdog_StartStop tests that the watchdog starts a process, creates a PID | |
// file, and stops the process when asked to. | |
func TestWatchdog_StartStop_successful(t *testing.T) { | |
wd := NewWatchdog("test.pid", "wd.pid", 100*time.Millisecond) | |
t.Cleanup(func() { | |
os.Remove("test.pid") | |
os.Remove("wd.pid") | |
}) | |
// Mock command that will sleep for 1 second. | |
cmd := exec.Command("sleep", "1") | |
errChan := make(chan error, 1) | |
go func() { | |
errChan <- wd.Start(cmd.Path, cmd.Args[1:]...) | |
}() | |
// Wait for process to start. | |
time.Sleep(200 * time.Millisecond) | |
// Verify process is running. | |
wd.cmdMutex.Lock() | |
require.NotNil(t, wd.cmd) | |
require.NotNil(t, wd.cmd.Process) | |
wd.cmdMutex.Unlock() | |
// Stop the watchdog. | |
wd.Stop() | |
// Verify no errors. | |
select { | |
case err := <-errChan: | |
require.NoError(t, err) | |
case <-time.After(500 * time.Millisecond): | |
t.Fatal("timeout waiting for Start to return") | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/watchdog/watchdog_test.go
Outdated
// TestWatchdog_StartStop tests that the watchdog starts a process, creates a PID | ||
// file, and stops the process when asked to. | ||
func TestWatchdog_StartStop(t *testing.T) { | ||
t.Run("successful start and graceful stop", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the test says that here actually two tests: for start and for stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@TarantoolBot document Title: add the tt tcm stop command. Add command tt tcm stop to gracefully terminate TCM: - Works in both modes(watchdog and interactive) - Stops all subprocesses Closes #TNTP-1993
2c979d4
to
544bbc1
Compare
What has been done? Why? What problem is being solved?
I didn't forget about (remove if it is not applicable):
Related issues:
Closes #TNTP-1992
Closes #TNTP-1993