2019-04-06 07:17:25 +00:00
|
|
|
//! Proxmox Server/Service framework
|
|
|
|
//!
|
|
|
|
//! This code provides basic primitives to build our REST API
|
|
|
|
//! services. We want async IO, so this is built on top of
|
|
|
|
//! tokio/hyper.
|
|
|
|
|
2020-11-02 18:18:36 +00:00
|
|
|
use anyhow::{format_err, Error};
|
2020-11-02 18:13:36 +00:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use nix::unistd::Pid;
|
2021-05-11 13:54:00 +00:00
|
|
|
use serde_json::Value;
|
2020-11-02 18:13:36 +00:00
|
|
|
|
|
|
|
use proxmox::sys::linux::procfs::PidStat;
|
2021-09-01 10:21:51 +00:00
|
|
|
use proxmox::tools::fs::{create_path, CreateOptions};
|
2020-11-02 18:13:36 +00:00
|
|
|
|
2021-07-06 09:56:35 +00:00
|
|
|
use pbs_buildcfg;
|
2020-11-02 18:13:36 +00:00
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref PID: i32 = unsafe { libc::getpid() };
|
|
|
|
static ref PSTART: u64 = PidStat::read_from_pid(Pid::from_raw(*PID)).unwrap().starttime;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pid() -> i32 {
|
|
|
|
*PID
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pstart() -> u64 {
|
|
|
|
*PSTART
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:18:36 +00:00
|
|
|
pub fn write_pid(pid_fn: &str) -> Result<(), Error> {
|
|
|
|
let pid_str = format!("{}\n", *PID);
|
2021-09-01 10:21:51 +00:00
|
|
|
proxmox::tools::fs::replace_file(pid_fn, pid_str.as_bytes(), CreateOptions::new())
|
2020-11-02 18:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read_pid(pid_fn: &str) -> Result<i32, Error> {
|
|
|
|
let pid = proxmox::tools::fs::file_get_contents(pid_fn)?;
|
|
|
|
let pid = std::str::from_utf8(&pid)?.trim();
|
|
|
|
pid.parse().map_err(|err| format_err!("could not parse pid - {}", err))
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:13:36 +00:00
|
|
|
pub fn ctrl_sock_from_pid(pid: i32) -> String {
|
2021-07-06 09:56:35 +00:00
|
|
|
format!("\0{}/control-{}.sock", pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR, pid)
|
2020-11-02 18:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn our_ctrl_sock() -> String {
|
|
|
|
ctrl_sock_from_pid(*PID)
|
|
|
|
}
|
|
|
|
|
2019-04-06 07:17:25 +00:00
|
|
|
mod environment;
|
|
|
|
pub use environment::*;
|
|
|
|
|
2019-04-08 16:43:26 +00:00
|
|
|
mod upid;
|
|
|
|
pub use upid::*;
|
|
|
|
|
2019-04-08 10:21:29 +00:00
|
|
|
mod state;
|
|
|
|
pub use state::*;
|
|
|
|
|
2019-04-08 15:59:39 +00:00
|
|
|
mod command_socket;
|
|
|
|
pub use command_socket::*;
|
|
|
|
|
2019-04-06 07:17:25 +00:00
|
|
|
mod worker_task;
|
|
|
|
pub use worker_task::*;
|
2019-04-08 10:21:29 +00:00
|
|
|
|
2019-06-26 15:29:12 +00:00
|
|
|
mod h2service;
|
|
|
|
pub use h2service::*;
|
|
|
|
|
2019-11-22 08:23:03 +00:00
|
|
|
pub mod config;
|
|
|
|
pub use config::*;
|
|
|
|
|
2019-04-06 07:17:25 +00:00
|
|
|
pub mod formatter;
|
2019-04-08 10:21:29 +00:00
|
|
|
|
2019-04-06 07:17:25 +00:00
|
|
|
#[macro_use]
|
|
|
|
pub mod rest;
|
|
|
|
|
2020-10-28 06:33:05 +00:00
|
|
|
pub mod jobstate;
|
|
|
|
|
|
|
|
mod verify_job;
|
|
|
|
pub use verify_job::*;
|
2020-10-27 12:36:56 +00:00
|
|
|
|
2020-10-30 08:07:24 +00:00
|
|
|
mod prune_job;
|
|
|
|
pub use prune_job::*;
|
|
|
|
|
2020-10-30 09:54:31 +00:00
|
|
|
mod gc_job;
|
|
|
|
pub use gc_job::*;
|
|
|
|
|
2020-10-27 12:36:56 +00:00
|
|
|
mod email_notifications;
|
|
|
|
pub use email_notifications::*;
|
2020-11-03 12:29:06 +00:00
|
|
|
|
|
|
|
mod report;
|
|
|
|
pub use report::*;
|
2020-11-16 13:37:22 +00:00
|
|
|
|
|
|
|
pub mod ticket;
|
2021-03-31 10:21:50 +00:00
|
|
|
|
|
|
|
pub mod auth;
|
2021-05-11 13:54:00 +00:00
|
|
|
|
2021-07-09 13:12:34 +00:00
|
|
|
pub mod pull;
|
|
|
|
|
2021-05-11 13:54:00 +00:00
|
|
|
pub(crate) async fn reload_proxy_certificate() -> Result<(), Error> {
|
2021-07-06 09:56:35 +00:00
|
|
|
let proxy_pid = crate::server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)?;
|
2021-05-11 13:54:00 +00:00
|
|
|
let sock = crate::server::ctrl_sock_from_pid(proxy_pid);
|
|
|
|
let _: Value = crate::server::send_raw_command(sock, "{\"command\":\"reload-certificate\"}\n")
|
|
|
|
.await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-06-02 11:27:01 +00:00
|
|
|
|
|
|
|
pub(crate) async fn notify_datastore_removed() -> Result<(), Error> {
|
2021-07-06 09:56:35 +00:00
|
|
|
let proxy_pid = crate::server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)?;
|
2021-06-02 11:27:01 +00:00
|
|
|
let sock = crate::server::ctrl_sock_from_pid(proxy_pid);
|
|
|
|
let _: Value = crate::server::send_raw_command(sock, "{\"command\":\"datastore-removed\"}\n")
|
|
|
|
.await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-09-01 10:21:51 +00:00
|
|
|
|
|
|
|
/// Create the base run-directory.
|
|
|
|
///
|
|
|
|
/// This exists to fixate the permissions for the run *base* directory while allowing intermediate
|
|
|
|
/// directories after it to have different permissions.
|
|
|
|
pub fn create_run_dir() -> Result<(), Error> {
|
2021-09-02 10:47:11 +00:00
|
|
|
let backup_user = pbs_config::backup_user()?;
|
2021-09-01 10:21:51 +00:00
|
|
|
let opts = CreateOptions::new()
|
|
|
|
.owner(backup_user.uid)
|
|
|
|
.group(backup_user.gid);
|
|
|
|
let _: bool = create_path(pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR_M!(), None, Some(opts))?;
|
|
|
|
Ok(())
|
|
|
|
}
|