]>
Commit | Line | Data |
---|---|---|
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 | 7 | use anyhow::{format_err, Error}; |
a68768cf TL |
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 | ||
04b053d8 TL |
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 | ||
a68768cf TL |
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 | ||
882594c5 DM |
48 | mod environment; |
49 | pub use environment::*; | |
50 | ||
634132fe DM |
51 | mod upid; |
52 | pub use upid::*; | |
53 | ||
7a630df7 DM |
54 | mod state; |
55 | pub use state::*; | |
56 | ||
78a39e05 DM |
57 | mod command_socket; |
58 | pub use command_socket::*; | |
59 | ||
882594c5 DM |
60 | mod worker_task; |
61 | pub use worker_task::*; | |
7a630df7 | 62 | |
42a87f7b DM |
63 | mod h2service; |
64 | pub use h2service::*; | |
65 | ||
e57e1cd8 DM |
66 | pub mod config; |
67 | pub use config::*; | |
68 | ||
882594c5 | 69 | pub mod formatter; |
7a630df7 | 70 | |
882594c5 DM |
71 | #[macro_use] |
72 | pub mod rest; | |
73 | ||
1298618a DM |
74 | pub mod jobstate; |
75 | ||
76 | mod verify_job; | |
77 | pub use verify_job::*; | |
b9e7bcc2 | 78 | |
b8d90798 HL |
79 | mod prune_job; |
80 | pub use prune_job::*; | |
81 | ||
3b707fbb DM |
82 | mod gc_job; |
83 | pub use gc_job::*; | |
84 | ||
b9e7bcc2 DM |
85 | mod email_notifications; |
86 | pub use email_notifications::*; | |
b0ef9631 HL |
87 | |
88 | mod report; | |
89 | pub use report::*; |