Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

TCM: Add tt tcm status/stop #1152

wants to merge 2 commits into from

Conversation

AlexandrLitkevich
Copy link
Contributor

@AlexandrLitkevich AlexandrLitkevich commented Apr 15, 2025

What has been done? Why? What problem is being solved?

I didn't forget about (remove if it is not applicable):

  • Well-written commit messages (see documentation how to write a commit message)
  • Don't forget about TarantoolBot in a commit message (see example)
  • Tests (see documentation for a testing package)
  • Changelog (see documentation for changelog format)
  • Documentation (see documentation for documentation style guide)

Related issues:

Closes #TNTP-1992
Closes #TNTP-1993

@AlexandrLitkevich AlexandrLitkevich force-pushed the TNTP-1992 branch 4 times, most recently from 68dc463 to 8f4ff5f Compare April 15, 2025 12:26
@AlexandrLitkevich AlexandrLitkevich added the full-ci Enables full ci tests label Apr 15, 2025
@AlexandrLitkevich AlexandrLitkevich changed the title Tntp 1992 TCM: Add tt tcm status/stop Apr 15, 2025
@AlexandrLitkevich AlexandrLitkevich force-pushed the TNTP-1992 branch 4 times, most recently from 61141f5 to 3923916 Compare April 16, 2025 05:41
@AlexandrLitkevich AlexandrLitkevich force-pushed the TNTP-1992 branch 2 times, most recently from 6a1d18d to 79fc7fb Compare April 16, 2025 11:30
CHANGELOG.md Outdated
Comment on lines 12 to 17
- `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.
Copy link
Contributor

@oleg-jukovec oleg-jukovec Apr 21, 2025

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

CHANGELOG.md Outdated
Comment on lines 121 to 130
- `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).
Copy link
Contributor

@oleg-jukovec oleg-jukovec Apr 21, 2025

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.

Copy link
Contributor Author

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.

oleg-jukovec

This comment was marked as duplicate.

@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
cli/cmd/tcm.go Outdated
Comment on lines 24 to 25
tcmPidFile = "tcmPidFile.pid"
watchdogPidFile = "watchdogPidFile.pid"
Copy link
Contributor

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.

Suggested change
tcmPidFile = "tcmPidFile.pid"
watchdogPidFile = "watchdogPidFile.pid"
tcmPidFile = "tcm.pid"
watchdogPidFile = "watchdog.pid"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +107 to +110
// 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 22 to 27
// 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
Copy link
Contributor

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.

Suggested change
// 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 14 to 52
// 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")
}
})
Copy link
Contributor

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.

Suggested change
// 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")
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full-ci Enables full ci tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants