move daemonize before creating account provider (#10003)

* move daemonize before creating account provider

* daemonize: add a future-proofing comment
This commit is contained in:
Andronik Ordian 2018-11-30 17:22:41 +03:00 committed by GitHub
parent 5acbcb0d57
commit 7af953fd62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -464,6 +464,14 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
let passwords = passwords_from_files(&cmd.acc_conf.password_files)?; let passwords = passwords_from_files(&cmd.acc_conf.password_files)?;
// Run in daemon mode.
// Note, that it should be called before we leave any file descriptor open,
// since `daemonize` will close them.
if let Some(pid_file) = cmd.daemon {
info!("Running as a daemon process!");
daemonize(pid_file)?;
}
// prepare account provider // prepare account provider
let account_provider = Arc::new(prepare_account_provider(&cmd.spec, &cmd.dirs, &spec.data_dir, cmd.acc_conf, &passwords)?); let account_provider = Arc::new(prepare_account_provider(&cmd.spec, &cmd.dirs, &spec.data_dir, cmd.acc_conf, &passwords)?);
@ -544,12 +552,6 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
// set network path. // set network path.
net_conf.net_config_path = Some(db_dirs.network_path().to_string_lossy().into_owned()); net_conf.net_config_path = Some(db_dirs.network_path().to_string_lossy().into_owned());
// run in daemon mode
if let Some(pid_file) = cmd.daemon {
info!("Running as a daemon process!");
daemonize(pid_file)?;
}
let restoration_db_handler = db::restoration_db_handler(&client_path, &client_config); let restoration_db_handler = db::restoration_db_handler(&client_path, &client_config);
let client_db = restoration_db_handler.open(&client_path) let client_db = restoration_db_handler.open(&client_path)
.map_err(|e| format!("Failed to open database {:?}", e))?; .map_err(|e| format!("Failed to open database {:?}", e))?;