From 7f2acedf9fce9cc0cb0383bf6027d46ec7e0448e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 18 Feb 2016 13:10:04 +0100 Subject: [PATCH] Reintroduce daemonize. --- Cargo.toml | 1 + parity/main.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index c58cacf0d..828ed32e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ ethsync = { path = "sync" } ethcore-rpc = { path = "rpc", optional = true } fdlimit = { path = "util/fdlimit" } target_info = "0.1" +daemonize = "0.2" [features] default = ["rpc"] diff --git a/parity/main.rs b/parity/main.rs index 8af61ca93..d0bc05a08 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -31,6 +31,7 @@ extern crate env_logger; extern crate ctrlc; extern crate fdlimit; extern crate target_info; +extern crate daemonize; #[cfg(feature = "rpc")] extern crate ethcore_rpc as rpc; @@ -49,6 +50,7 @@ use ethcore::ethereum; use ethcore::blockchain::CacheSize; use ethsync::EthSync; use target_info::Target; +use daemonize::{Daemonize}; docopt!(Args derive Debug, " Parity. Ethereum Client. @@ -56,6 +58,7 @@ Parity. Ethereum Client. Copyright 2015, 2016 Ethcore (UK) Limited Usage: + parity daemon [options] [ --no-bootstrap | ... ] parity [options] [ --no-bootstrap | ... ] Options: @@ -183,6 +186,21 @@ impl Configuration { print_version(); return; } + if self.args.cmd_daemon { + let daemonize = Daemonize::new() + .pid_file("/tmp/parity.pid") // Every method except `new` and `start` + .chown_pid_file(true) // is optional, see `Daemonize` documentation + .working_directory("/tmp") // for default behaviour. + .user("nobody") + .group("daemon") // Group name + .group(2) // Or group id + .privileged_action(|| "Executed before drop privileges"); + + match daemonize.start() { + Ok(_) => info!("Success, daemonized"), + Err(e) => { error!("{}", e); return; }, + } + } self.execute_client(); }