]> git.proxmox.com Git - proxmox-backup.git/blame - src/server.rs
server: write main daemon PID to run directory
[proxmox-backup.git] / src / server.rs
CommitLineData
882594c5
DM
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
04b053d8 7use anyhow::{format_err, Error};
a68768cf
TL
8use lazy_static::lazy_static;
9use nix::unistd::Pid;
10
11use proxmox::sys::linux::procfs::PidStat;
12
13use crate::buildcfg;
14
15lazy_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
20pub fn pid() -> i32 {
21 *PID
22}
23
24pub fn pstart() -> u64 {
25 *PSTART
26}
27
04b053d8
TL
28pub 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
34pub 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
a68768cf
TL
40pub fn ctrl_sock_from_pid(pid: i32) -> String {
41 format!("\0{}/control-{}.sock", buildcfg::PROXMOX_BACKUP_RUN_DIR, pid)
42}
43
44pub fn our_ctrl_sock() -> String {
45 ctrl_sock_from_pid(*PID)
46}
47
882594c5
DM
48mod environment;
49pub use environment::*;
50
634132fe
DM
51mod upid;
52pub use upid::*;
53
7a630df7
DM
54mod state;
55pub use state::*;
56
78a39e05
DM
57mod command_socket;
58pub use command_socket::*;
59
882594c5
DM
60mod worker_task;
61pub use worker_task::*;
7a630df7 62
42a87f7b
DM
63mod h2service;
64pub use h2service::*;
65
e57e1cd8
DM
66pub mod config;
67pub use config::*;
68
882594c5 69pub mod formatter;
7a630df7 70
882594c5
DM
71#[macro_use]
72pub mod rest;
73
1298618a
DM
74pub mod jobstate;
75
76mod verify_job;
77pub use verify_job::*;
b9e7bcc2 78
b8d90798
HL
79mod prune_job;
80pub use prune_job::*;
81
3b707fbb
DM
82mod gc_job;
83pub use gc_job::*;
84
b9e7bcc2
DM
85mod email_notifications;
86pub use email_notifications::*;