Skip to content

logrotate: fix log rotation #1175

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 1 commit into
base: master
Choose a base branch
from
Open

Conversation

elhimov
Copy link
Contributor

@elhimov elhimov commented Jun 18, 2025

Watchdog launches tarantool in a way that produce log to stderr and thus tarantool itself does nothing to handle log rotation, it is handled entirely at watchdog side.
Prior to this patch os.File was used in Cmd.Stdout, when watchdog launches tarantool binary and according to golang documentation (see Exec.Cmd.Stdout) in this special case output from the child process is connected directly to that file. It means that even if it is closed at watchdog side, its child process (tarantool) keeps using the original one, i.e. it proceeds with logging to the original file even after renaming it.
Now Logger is used as Cmd.Stdout, and according to the mentioned documentation separate goroutine reads output from the child process over a pipe and delivers that data to the Logger. It allows proper handling of log rotation at watchdog side.

@TarantoolBot document
Title: tt logrotate properly release descriptor of the old log file.

I didn't forget about:

  • 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)

Related issues:

Closes #1174

@elhimov elhimov force-pushed the elhimov/gh-1174-fix-logrotate branch 2 times, most recently from 9feeede to 5bab0d2 Compare June 18, 2025 14:56
@elhimov elhimov added the full-ci Enables full ci tests label Jun 18, 2025
Watchdog launches tarantool in a way that produce log to stderr and thus
tarantool itself does nothing to handle log rotation, it is handled
entirely at watchdog side.
Prior to this patch `os.File` was used in `Cmd.Stdout`, when watchdog
launches tarantool binary and according to golang documentation
(see `Exec.Cmd.Stdout`) in this special case output from the child
process is connected directly to that file. It means that even if it is
closed at watchdog side, its child process (tarantool) keeps using the
original one, i.e. it proceeds with logging to the original file even
after renaming it.
Now `Logger` is used as `Cmd.Stdout`, and according to the mentioned
documentation separate goroutine reads output from the child process
over a pipe and delivers that data to the `Logger`. It allows proper
handling of log rotation at watchdog side.

Closes #1174

@TarantoolBot document
Title: `tt logrotate` properly release descriptor of the old log file.
@elhimov elhimov force-pushed the elhimov/gh-1174-fix-logrotate branch from 5bab0d2 to da042d0 Compare June 19, 2025 06:58
Comment on lines +113 to +114
inst.stdOut = logger
inst.stdErr = logger
Copy link
Contributor

@oleg-jukovec oleg-jukovec Jun 19, 2025

Choose a reason for hiding this comment

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

tt/cli/running/running.go

Lines 761 to 762 in da042d0

StdOutOpt(stdOut),
StdErrOpt(stdErr),

But stdOut may be overwritten. Is it problem?

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.

logrotate: log file descriptor is not released after log rotation
2 participants