split out pbs-runtime module

These are mostly tokio specific "hacks" or "workarounds" we
only really need/want in our binaries without pulling it in
via our library crates.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2021-07-06 12:08:44 +02:00
parent 01fd2447b2
commit d420962fbc
26 changed files with 50 additions and 37 deletions

View File

@ -18,7 +18,7 @@ use proxmox_backup::config;
fn main() {
proxmox_backup::tools::setup_safe_path_env();
if let Err(err) = proxmox_backup::tools::runtime::main(run()) {
if let Err(err) = pbs_runtime::main(run()) {
eprintln!("Error: {}", err);
std::process::exit(-1);
}

View File

@ -1494,6 +1494,6 @@ fn main() {
let rpcenv = CliEnvironment::new();
run_cli_command(cmd_def, rpcenv, Some(|future| {
proxmox_backup::tools::runtime::main(future)
pbs_runtime::main(future)
}));
}

View File

@ -397,7 +397,7 @@ fn main() {
let mut rpcenv = CliEnvironment::new();
rpcenv.set_auth_id(Some(String::from("root@pam")));
proxmox_backup::tools::runtime::main(run_async_cli_command(cmd_def, rpcenv));
pbs_runtime::main(run_async_cli_command(cmd_def, rpcenv));
}
// shell completion helper
@ -408,7 +408,7 @@ pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap<String, String
let _ = proxmox::try_block!({
let remote = param.get("remote").ok_or_else(|| format_err!("no remote"))?;
let data = crate::tools::runtime::block_on(async move {
let data = pbs_runtime::block_on(async move {
crate::api2::config::remote::scan_remote_datastores(remote.clone()).await
})?;

View File

@ -65,7 +65,7 @@ fn main() -> Result<(), Error> {
bail!("proxy not running as backup user or group (got uid {} gid {})", running_uid, running_gid);
}
proxmox_backup::tools::runtime::main(run())
pbs_runtime::main(run())
}
async fn run() -> Result<(), Error> {
@ -700,7 +700,7 @@ async fn schedule_task_log_rotate() {
if logrotate.rotate(max_size, None, Some(max_files))? {
println!("rotated access log, telling daemons to re-open log file");
proxmox_backup::tools::runtime::block_on(command_reopen_logfiles())?;
pbs_runtime::block_on(command_reopen_logfiles())?;
worker.log("API access log was rotated".to_string());
} else {
worker.log("API access log was not rotated".to_string());
@ -787,7 +787,7 @@ async fn generate_host_stats(save: bool) {
use proxmox_backup::config::datastore;
proxmox_backup::tools::runtime::block_in_place(move || {
pbs_runtime::block_in_place(move || {
match read_proc_stat() {
Ok(stat) => {

View File

@ -91,7 +91,7 @@ fn main() {
let mut rpcenv = CliEnvironment::new();
rpcenv.set_auth_id(Some(String::from("root@pam")));
if let Err(err) = proxmox_backup::tools::runtime::main(do_update(&mut rpcenv)) {
if let Err(err) = pbs_runtime::main(do_update(&mut rpcenv)) {
eprintln!("error during update: {}", err);
std::process::exit(1);
}

View File

@ -473,6 +473,6 @@ fn main() {
run_cli_command(
cmd_def,
rpcenv,
Some(|future| proxmox_backup::tools::runtime::main(future)),
Some(|future| pbs_runtime::main(future)),
);
}

View File

@ -62,7 +62,7 @@ fn main() -> Result<(), Error> {
info!("disk scan complete, starting main runtime...");
proxmox_backup::tools::runtime::main(run())
pbs_runtime::main(run())
}
async fn run() -> Result<(), Error> {

View File

@ -1101,5 +1101,5 @@ fn main() {
let mut rpcenv = CliEnvironment::new();
rpcenv.set_auth_id(Some(String::from("root@pam")));
proxmox_backup::tools::runtime::main(run_async_cli_command(cmd_def, rpcenv));
pbs_runtime::main(run_async_cli_command(cmd_def, rpcenv));
}

View File

@ -139,7 +139,7 @@ fn mount(
if verbose {
// This will stay in foreground with debug output enabled as None is
// passed for the RawFd.
return proxmox_backup::tools::runtime::main(mount_do(param, None));
return pbs_runtime::main(mount_do(param, None));
}
// Process should be daemonized.
@ -155,7 +155,7 @@ fn mount(
Ok(ForkResult::Child) => {
drop(pr);
nix::unistd::setsid().unwrap();
proxmox_backup::tools::runtime::main(mount_do(param, Some(pw)))
pbs_runtime::main(mount_do(param, Some(pw)))
}
Err(_) => bail!("failed to daemonize process"),
}

View File

@ -107,7 +107,7 @@ pub async fn try_get(repo: &BackupRepository, url: &str) -> Value {
}
pub fn complete_backup_group(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
proxmox_backup::tools::runtime::main(async { complete_backup_group_do(param).await })
pbs_runtime::main(async { complete_backup_group_do(param).await })
}
pub async fn complete_backup_group_do(param: &HashMap<String, String>) -> Vec<String> {
@ -137,7 +137,7 @@ pub async fn complete_backup_group_do(param: &HashMap<String, String>) -> Vec<St
}
pub fn complete_group_or_snapshot(arg: &str, param: &HashMap<String, String>) -> Vec<String> {
proxmox_backup::tools::runtime::main(async { complete_group_or_snapshot_do(arg, param).await })
pbs_runtime::main(async { complete_group_or_snapshot_do(arg, param).await })
}
pub async fn complete_group_or_snapshot_do(arg: &str, param: &HashMap<String, String>) -> Vec<String> {
@ -156,7 +156,7 @@ pub async fn complete_group_or_snapshot_do(arg: &str, param: &HashMap<String, St
}
pub fn complete_backup_snapshot(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
proxmox_backup::tools::runtime::main(async { complete_backup_snapshot_do(param).await })
pbs_runtime::main(async { complete_backup_snapshot_do(param).await })
}
pub async fn complete_backup_snapshot_do(param: &HashMap<String, String>) -> Vec<String> {
@ -188,7 +188,7 @@ pub async fn complete_backup_snapshot_do(param: &HashMap<String, String>) -> Vec
}
pub fn complete_server_file_name(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
proxmox_backup::tools::runtime::main(async { complete_server_file_name_do(param).await })
pbs_runtime::main(async { complete_server_file_name_do(param).await })
}
pub async fn complete_server_file_name_do(param: &HashMap<String, String>) -> Vec<String> {
@ -279,7 +279,7 @@ pub fn complete_chunk_size(_arg: &str, _param: &HashMap<String, String>) -> Vec<
}
pub fn complete_auth_id(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
proxmox_backup::tools::runtime::main(async { complete_auth_id_do(param).await })
pbs_runtime::main(async { complete_auth_id_do(param).await })
}
pub async fn complete_auth_id_do(param: &HashMap<String, String>) -> Vec<String> {

View File

@ -491,6 +491,6 @@ fn main() {
let rpcenv = CliEnvironment::new();
run_cli_command(cmd_def, rpcenv, Some(|future| {
proxmox_backup::tools::runtime::main(future)
pbs_runtime::main(future)
}));
}