]> git.proxmox.com Git - proxmox-backup.git/blob - src/server.rs
bump version to 1.0.2-1
[proxmox-backup.git] / src / server.rs
1 //! Proxmox Server/Service framework
2 //!
3 //! This code provides basic primitives to build our REST API
4 //! services. We want async IO, so this is built on top of
5 //! tokio/hyper.
6
7 use anyhow::{format_err, Error};
8 use lazy_static::lazy_static;
9 use nix::unistd::Pid;
10
11 use proxmox::sys::linux::procfs::PidStat;
12
13 use crate::buildcfg;
14
15 lazy_static! {
16 static ref PID: i32 = unsafe { libc::getpid() };
17 static ref PSTART: u64 = PidStat::read_from_pid(Pid::from_raw(*PID)).unwrap().starttime;
18 }
19
20 pub fn pid() -> i32 {
21 *PID
22 }
23
24 pub fn pstart() -> u64 {
25 *PSTART
26 }
27
28 pub fn write_pid(pid_fn: &str) -> Result<(), Error> {
29 let pid_str = format!("{}\n", *PID);
30 let opts = proxmox::tools::fs::CreateOptions::new();
31 proxmox::tools::fs::replace_file(pid_fn, pid_str.as_bytes(), opts)
32 }
33
34 pub fn read_pid(pid_fn: &str) -> Result<i32, Error> {
35 let pid = proxmox::tools::fs::file_get_contents(pid_fn)?;
36 let pid = std::str::from_utf8(&pid)?.trim();
37 pid.parse().map_err(|err| format_err!("could not parse pid - {}", err))
38 }
39
40 pub fn ctrl_sock_from_pid(pid: i32) -> String {
41 format!("\0{}/control-{}.sock", buildcfg::PROXMOX_BACKUP_RUN_DIR, pid)
42 }
43
44 pub fn our_ctrl_sock() -> String {
45 ctrl_sock_from_pid(*PID)
46 }
47
48 mod environment;
49 pub use environment::*;
50
51 mod upid;
52 pub use upid::*;
53
54 mod state;
55 pub use state::*;
56
57 mod command_socket;
58 pub use command_socket::*;
59
60 mod worker_task;
61 pub use worker_task::*;
62
63 mod h2service;
64 pub use h2service::*;
65
66 pub mod config;
67 pub use config::*;
68
69 pub mod formatter;
70
71 #[macro_use]
72 pub mod rest;
73
74 pub mod jobstate;
75
76 mod verify_job;
77 pub use verify_job::*;
78
79 mod prune_job;
80 pub use prune_job::*;
81
82 mod gc_job;
83 pub use gc_job::*;
84
85 mod email_notifications;
86 pub use email_notifications::*;
87
88 mod report;
89 pub use report::*;