Skip to content

tt: daemon module #129

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

Merged
merged 2 commits into from
Nov 15, 2022
Merged

tt: daemon module #129

merged 2 commits into from
Nov 15, 2022

Conversation

AnaNek
Copy link
Contributor

@AnaNek AnaNek commented Sep 5, 2022

tt daemon module is used to manage HTTP server
running on the background. HTTP server can process
tt commands such as start, status, etc.
Daemon can be configurated with tt_daemon.yaml config.

tt_daemon.yaml file format:

  daemon:
        run_dir: path
        log_dir: path
        log_maxsize: num (MB)
        log_maxage: num (Days)
        log_maxbackups: num
        log_file: string (file name)
        listen_interface: string
        port: num
        pidfile: string (file name)

The following set of commands is implemented:

  • tt daemon start - launch of a daemon;
  • tt daemon stop - terminate of the daemon;
  • tt daemon status - get daemon status;
  • tt daemon restart - daemon restart.

Closes #10

@AnaNek AnaNek marked this pull request as draft September 5, 2022 10:07
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch 4 times, most recently from fd13505 to 8f6c578 Compare September 5, 2022 11:40
@AnaNek AnaNek requested a review from 0x501D September 5, 2022 11:42
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch 8 times, most recently from 7a6bc08 to dfd9192 Compare September 14, 2022 00:53
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch 7 times, most recently from aac5b07 to 6bd63a1 Compare September 15, 2022 19:07
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch from 6bd63a1 to 33d81b9 Compare September 20, 2022 13:17
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch 4 times, most recently from 22ead1c to 2ca4747 Compare October 20, 2022 09:43
Copy link
Member

@0x501D 0x501D left a comment

Choose a reason for hiding this comment

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

LGTM

@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch 4 times, most recently from e8e036f to 6768fc5 Compare October 26, 2022 19:03
Copy link
Contributor

@LeonidVas LeonidVas left a comment

Choose a reason for hiding this comment

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

Hi! Thank you for the patchset. I reviewed the patches and left a few comments. Take a look at these, and I'll continue to explore the patch set.
And rebase the branch to the master.

@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch from 6768fc5 to bf83f33 Compare November 8, 2022 13:42
@AnaNek AnaNek requested a review from LeonidVas November 8, 2022 14:27
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch 5 times, most recently from 3a8fa03 to 7f67ae0 Compare November 11, 2022 13:51
@AnaNek AnaNek requested a review from LeonidVas November 12, 2022 04:59
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch from 7f67ae0 to d64e462 Compare November 15, 2022 08:22
The watchdog process (the child) inherits copies of
the parent's stdout/stderr open file descriptors.
`tt start` starts instances on the background,
so watchdog processes are running after `tt start`
and `tt` will hang forever, because stdout fd of
child process would not be closed.

Part of #10
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch from d64e462 to 08c6531 Compare November 15, 2022 08:25
"strings"
"syscall"
"time"

"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/config"
"github.com/tarantool/tt/cli/configure"
"github.com/tarantool/tt/cli/process_utils"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just github.com/tarantool/tt/cli/process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is because we have type Process in daemon/process.go, having process package and type process in different package causes confusion.

}

// StopProcess stops the process by pidFile.
func StopProcess(pidFile, consoleSocket, processName string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Only the PID is needed to stop the process by PID, the other arguments must not be passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed StopProcess:

// StopProcess stops the process by pidFile.
func StopProcess(pidFile string) (int, error) {
pid, err := GetPIDFromFile(pidFile)
if err != nil {
return 0, err
}
alive, err := IsProcessAlive(pid)
if !alive {
return 0, fmt.Errorf(`The process is already dead. Error: "%v".`, err)
}
if err = syscall.Kill(pid, syscall.SIGINT); err != nil {
return 0, fmt.Errorf(`Can't terminate the process. Error: "%v".`, err)
}
if res := waitProcessTermination(pid, 30*time.Second, 100*time.Millisecond); !res {
return 0, fmt.Errorf("Can't terminate the process.")
}
return pid, nil
}

// should be found on to bind http server socket.
ListenInterface string
// Control UNIX socket for started instance.
ConsoleSocket string
Copy link
Contributor

Choose a reason for hiding this comment

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

image
It looks like the field has not been deleted)

@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch from 08c6531 to 3503a04 Compare November 15, 2022 12:41
`tt daemon` module is used to manage HTTP server
running on the background. HTTP server can process
`tt` commands such as `start`, `status`, etc.
Daemon can be configurated with `tt_daemon.yaml` config.

The following set of commands is implemented:

* `tt daemon start` - launch of a daemon;
* `tt daemon stop` - terminate of the daemon;
* `tt daemon status` - get daemon status;
* `tt daemon restart` - daemon restart.

Closes #10
@AnaNek AnaNek force-pushed the AnaNek/gh-10-daemon branch from 3503a04 to f2224f7 Compare November 15, 2022 12:49
@LeonidVas LeonidVas added the full-ci Enables full ci tests label Nov 15, 2022
@LeonidVas LeonidVas merged commit ed96be8 into master Nov 15, 2022
@LeonidVas LeonidVas deleted the AnaNek/gh-10-daemon branch November 15, 2022 13:59
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.

tt daemon
3 participants