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;
|
|
|
|
|
|
|
|
use proxmox::sys::linux::procfs::PidStat;
|
|
|
|
|
|
|
|
use crate::buildcfg;
|
|
|
|
|
|
|
|
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);
|
|
|
|
let opts = proxmox::tools::fs::CreateOptions::new();
|
|
|
|
proxmox::tools::fs::replace_file(pid_fn, pid_str.as_bytes(), opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
format!("\0{}/control-{}.sock", buildcfg::PROXMOX_BACKUP_RUN_DIR, pid)
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|