2 use serde_json
::{json, Value}
;
4 use proxmox
::api
::{cli::*, RpcEnvironment, ApiHandler}
;
6 use proxmox_backup
::api2
;
7 use proxmox_backup
::tools
::subscription
;
9 async
fn wait_for_local_worker(upid_str
: &str) -> Result
<(), Error
> {
10 let upid
: proxmox_backup
::server
::UPID
= upid_str
.parse()?
;
11 let sleep_duration
= core
::time
::Duration
::new(0, 100_000_000);
14 if !proxmox_backup
::server
::worker_is_active_local(&upid
) {
17 tokio
::time
::sleep(sleep_duration
).await
;
24 rpcenv
: &mut dyn RpcEnvironment
,
25 ) -> Result
<Value
, Error
> {
26 let param
= json
!({}
);
28 let method
= &api2
::node
::subscription
::API_METHOD_CHECK_SUBSCRIPTION
;
29 let _res
= match method
.handler
{
30 ApiHandler
::Sync(handler
) => (handler
)(param
, method
, rpcenv
)?
,
34 let notify
= match subscription
::read_subscription() {
35 Ok(Some(subscription
)) => subscription
.status
== subscription
::SubscriptionStatus
::ACTIVE
,
38 eprintln
!("Error reading subscription - {}", err
);
46 let method
= &api2
::node
::apt
::API_METHOD_APT_UPDATE_DATABASE
;
47 let upid
= match method
.handler
{
48 ApiHandler
::Sync(handler
) => (handler
)(param
, method
, rpcenv
)?
,
51 wait_for_local_worker(upid
.as_str().unwrap()).await?
;
53 match check_acme_certificates(rpcenv
).await
{
56 eprintln
!("error checking certificates: {}", err
);
60 // TODO: cleanup tasks like in PVE?
65 async
fn check_acme_certificates(rpcenv
: &mut dyn RpcEnvironment
) -> Result
<(), Error
> {
66 let (config
, _
) = proxmox_backup
::config
::node
::config()?
;
68 // do we even have any acme domains configures?
69 if config
.acme_domains().next().is_none() {
73 if !api2
::node
::certificates
::cert_expires_soon()?
{
74 println
!("Certificate does not expire within the next 30 days, not renewing.");
78 let info
= &api2
::node
::certificates
::API_METHOD_RENEW_ACME_CERT
;
79 let result
= match info
.handler
{
80 ApiHandler
::Sync(handler
) => (handler
)(json
!({}
), info
, rpcenv
)?
,
83 wait_for_local_worker(result
.as_str().unwrap()).await?
;
89 proxmox_backup
::tools
::setup_safe_path_env();
91 let mut rpcenv
= CliEnvironment
::new();
92 rpcenv
.set_auth_id(Some(String
::from("root@pam")));
94 if let Err(err
) = pbs_runtime
::main(do_update(&mut rpcenv
)) {
95 eprintln
!("error during update: {}", err
);
96 std
::process
::exit(1);