Skip to content
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

Add daemonize feature #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ path = "src/bin/cli.rs"
required-features = ["jsonrpc_server"]

[features]
default = ["jsonrpc_server"]
default = ["jsonrpc_server", "daemonize"]
jsonrpc_server = ["jsonrpc-core", "jsonrpc-derive", "mio"]
daemonize = ["daemonize-simple"]

[dependencies]
revault_tx = { git = "https://github.com/revault/revault_tx", features = ["use-serde"] }
Expand All @@ -36,7 +37,7 @@ backtrace = "0.3"
dirs = "3.0"

# It's concise, does the Right Thing, and even supports Windows !
daemonize-simple = "0.1"
daemonize-simple = { version = "0.1", optional = true }

# To talk to bitcoind
jsonrpc = "0.12"
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ use std::{
thread,
};

use daemonize_simple::Daemonize;

// A panic in any thread should stop the main thread, and print the panic.
fn setup_panic_hook() {
panic::set_hook(Box::new(move |panic_info| {
Expand Down Expand Up @@ -196,17 +194,19 @@ impl DaemonHandle {

// NOTE: it's safe to daemonize now, as we don't carry any open DB connection
// https://www.sqlite.org/howtocorrupt.html#_carrying_an_open_database_connection_across_a_fork_

#[cfg(feature = "daemonize")]
if revaultd.daemon {
log::info!("Daemonizing");
let log_file = revaultd.log_file();
let daemon = Daemonize {
let daemon = daemonize_simple::Daemonize {
// TODO: Make this configurable for inits
pid_file: Some(revaultd.pid_file()),
stdout_file: Some(log_file.clone()),
stderr_file: Some(log_file),
chdir: Some(revaultd.data_dir.clone()),
append: true,
..Daemonize::default()
..daemonize_simple::Daemonize::default()
};
daemon.doit().unwrap_or_else(|e| {
// The panic hook will log::error
Expand Down