Skip to content

Conversation

@Eshaan-byte
Copy link

@Eshaan-byte Eshaan-byte commented Dec 1, 2025

I hereby agree to the terms of the GreptimeDB CLA.

Related Issues

#7314

Summary of changes:

  • Added --daemon / -d CLI flag to greptime standalone start command
  • Added daemon: bool config option in StandaloneOptions for config file support
  • Implemented daemonization logic using the daemonize crate (v0.5)
  • Log redirection: stdout and stderr are redirected to logs/greptime.stdout and logs/greptimedb.stderr in the data_home directory
  • Unix-only implementation using #[cfg(unix)] conditional compilation

How does this PR work?

When the --daemon flag is passed or daemon = true is set in the config file:

  1. The process creates the necessary log directories
  2. Opens log files for stdout/stderr redirection
  3. Calls daemonize.start() which:
    • Forks the process
    • Detaches from the controlling terminal (setsid)
    • Changes working directory to data_home
    • Redirects stdout/stderr to the log files
  4. The parent process exits, leaving the child running as a daemon

Design decisions:

  • No PID file management: Kept simple as suggested by maintainers
  • Unix-only: Windows doesn't support daemonization in the same way (would require Windows services)
  • Log location: Uses existing logging.dir configuration, defaults to {data_home}/logs/

Example usage:

greptime standalone start --daemon
Config file:
[standalone]
daemon = true

PR Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

Implement native daemonization support for GreptimeDB standalone mode
to allow the process to run independently of shell sessions.

Changes:
- Add daemonize crate dependency (Unix-only)
- Add --daemon/-d CLI flag to standalone start command
- Add daemon configuration option to StandaloneOptions
- Implement daemonization with proper stdout/stderr redirection
- Redirect logs to data_home/logs/greptime.stdout and greptimedb.stderr

This addresses the need for resilient background execution on embedded
and edge deployments, especially on ARM64 boards where systemd may not
be available.

Fixes GreptimeTeam#7314

Signed-off-by: Eshaan <eshaan28gupta@gmail.com>
Fixed compilation errors in the daemonize function:
- Use correct SNAFU context pattern for FileIoSnafu
- Wrap daemonize errors in PlainError and BoxedError for proper error handling
- Follow codebase conventions for error context chaining

Signed-off-by: Eshaan <eshaan28gupta@gmail.com>
@Eshaan-byte Eshaan-byte requested a review from a team as a code owner December 1, 2025 01:44
@github-actions github-actions bot added size/XS docs-not-required This change does not impact docs. labels Dec 1, 2025
@evenyag evenyag requested review from killme2008 and sunng87 December 1, 2025 09:40
@evenyag
Copy link
Contributor

evenyag commented Dec 1, 2025

Hi, please sign your commits to pass the DCO.
https://github.com/GreptimeTeam/greptimedb/pull/7317/checks?check_run_id=56746535242

let daemonize = Daemonize::new()
.working_directory(data_home)
.stdout(stdout)
.stderr(stderr);
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep a pid file so we can implement greptime standalone stop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants