proxmox-daily-update: setup worker and command socket

This commit is contained in:
Dietmar Maurer 2021-09-23 11:12:27 +02:00
parent b9700a9fe5
commit b0e20a71e2
1 changed files with 17 additions and 4 deletions

View File

@ -1,7 +1,8 @@
use anyhow::Error;
use serde_json::{json, Value};
use serde_json::json;
use proxmox::api::{cli::*, RpcEnvironment, ApiHandler};
use proxmox::tools::fs::CreateOptions;
use proxmox_backup::api2;
use proxmox_backup::tools::subscription;
@ -22,7 +23,7 @@ async fn wait_for_local_worker(upid_str: &str) -> Result<(), Error> {
/// Daily update
async fn do_update(
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
) -> Result<(), Error> {
let param = json!({});
let method = &api2::node::subscription::API_METHOD_CHECK_SUBSCRIPTION;
@ -59,7 +60,7 @@ async fn do_update(
// TODO: cleanup tasks like in PVE?
Ok(Value::Null)
Ok(())
}
async fn check_acme_certificates(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
@ -85,13 +86,25 @@ async fn check_acme_certificates(rpcenv: &mut dyn RpcEnvironment) -> Result<(),
Ok(())
}
async fn run(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
let backup_user = pbs_config::backup_user()?;
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
proxmox_rest_server::init_worker_tasks(pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(), file_opts.clone())?;
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
commando_sock.spawn()?;
do_update(rpcenv).await
}
fn main() {
proxmox_backup::tools::setup_safe_path_env();
let mut rpcenv = CliEnvironment::new();
rpcenv.set_auth_id(Some(String::from("root@pam")));
if let Err(err) = pbs_runtime::main(do_update(&mut rpcenv)) {
if let Err(err) = pbs_runtime::main(run(&mut rpcenv)) {
eprintln!("error during update: {}", err);
std::process::exit(1);
}