mirror of
https://github.com/DNSCrypt/encrypted-dns-server.git
synced 2024-05-21 15:56:06 +02:00
Revert "Remove daemonization, it's always been broken"
This reverts commit 4f22725931
.
This commit is contained in:
parent
4f22725931
commit
78eb2719ab
|
@ -17,6 +17,7 @@ byteorder = "1.4.2"
|
||||||
clap = { version = "2.33.3", default-features = false, features = ["wrap_help"] }
|
clap = { version = "2.33.3", default-features = false, features = ["wrap_help"] }
|
||||||
clockpro-cache = "0.1.10"
|
clockpro-cache = "0.1.10"
|
||||||
coarsetime = "0.1.18"
|
coarsetime = "0.1.18"
|
||||||
|
daemonize-simple = "0.1.5"
|
||||||
derivative = "2.2.0"
|
derivative = "2.2.0"
|
||||||
dnsstamps = "0.1.6"
|
dnsstamps = "0.1.6"
|
||||||
env_logger = { version = "0.8.3", default-features = false, features = ["humantime"] }
|
env_logger = { version = "0.8.3", default-features = false, features = ["humantime"] }
|
||||||
|
|
|
@ -90,6 +90,16 @@ cache_ttl_error = 600
|
||||||
client_ttl_holdon = 60
|
client_ttl_holdon = 60
|
||||||
|
|
||||||
|
|
||||||
|
## Run as a background process
|
||||||
|
|
||||||
|
daemonize = false
|
||||||
|
|
||||||
|
|
||||||
|
## Log file, when running as a background process
|
||||||
|
|
||||||
|
# log_file = "/tmp/encrypted-dns.log"
|
||||||
|
|
||||||
|
|
||||||
## PID file
|
## PID file
|
||||||
|
|
||||||
# pid_file = "/tmp/encrypted-dns.pid"
|
# pid_file = "/tmp/encrypted-dns.pid"
|
||||||
|
|
|
@ -78,6 +78,7 @@ pub struct Config {
|
||||||
pub filtering: FilteringConfig,
|
pub filtering: FilteringConfig,
|
||||||
pub dnscrypt: DNSCryptConfig,
|
pub dnscrypt: DNSCryptConfig,
|
||||||
pub tls: TLSConfig,
|
pub tls: TLSConfig,
|
||||||
|
pub daemonize: bool,
|
||||||
pub pid_file: Option<PathBuf>,
|
pub pid_file: Option<PathBuf>,
|
||||||
pub log_file: Option<PathBuf>,
|
pub log_file: Option<PathBuf>,
|
||||||
pub my_ip: Option<String>,
|
pub my_ip: Option<String>,
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -466,6 +466,9 @@ fn bind_listeners(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn privdrop(config: &Config) -> Result<(), Error> {
|
fn privdrop(config: &Config) -> Result<(), Error> {
|
||||||
|
if config.daemonize && config.metrics.is_some() {
|
||||||
|
bail!("Metrics are incompatible with daemonization - set 'daemonize = false' in the configuration file if you need metrics.");
|
||||||
|
}
|
||||||
let mut pd = PrivDrop::default();
|
let mut pd = PrivDrop::default();
|
||||||
if let Some(user) = &config.user {
|
if let Some(user) = &config.user {
|
||||||
pd = pd.user(user);
|
pd = pd.user(user);
|
||||||
|
@ -474,12 +477,27 @@ fn privdrop(config: &Config) -> Result<(), Error> {
|
||||||
pd = pd.group(group);
|
pd = pd.group(group);
|
||||||
}
|
}
|
||||||
if let Some(chroot) = &config.chroot {
|
if let Some(chroot) = &config.chroot {
|
||||||
|
if !config.daemonize {
|
||||||
pd = pd.chroot(chroot);
|
pd = pd.chroot(chroot);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if config.user.is_some() || config.group.is_some() || config.chroot.is_some() {
|
if config.user.is_some() || config.group.is_some() || config.chroot.is_some() {
|
||||||
info!("Dropping privileges");
|
info!("Dropping privileges");
|
||||||
pd.apply()?;
|
pd.apply()?;
|
||||||
}
|
}
|
||||||
|
if config.daemonize {
|
||||||
|
let mut daemon = daemonize_simple::Daemonize::default();
|
||||||
|
daemon.stdout_file = config.log_file.clone();
|
||||||
|
daemon.stderr_file = config.log_file.clone();
|
||||||
|
daemon.pid_file = config.pid_file.clone();
|
||||||
|
if let Some(chroot) = &config.chroot {
|
||||||
|
daemon.chdir = Some(chroot.into());
|
||||||
|
daemon.chroot = true;
|
||||||
|
}
|
||||||
|
daemon
|
||||||
|
.doit()
|
||||||
|
.map_err(|e| anyhow!("Unable to daemonize: [{}]", e))?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue