]> git.proxmox.com Git - proxmox-backup.git/blob - src/tools/systemd/types.rs
d44af70e51fd0197de4aa3c51649a2a2ceb72303
[proxmox-backup.git] / src / tools / systemd / types.rs
1 use serde::{Serialize, Deserialize};
2
3 use proxmox::api::{ api, schema::* };
4 use pbs_api_types::SINGLE_LINE_COMMENT_FORMAT;
5
6 pub const SYSTEMD_SECTION_NAME_SCHEMA: Schema = StringSchema::new(
7 "Section name")
8 .format(&ApiStringFormat::Enum(&[
9 EnumEntry::new("Unit", "Unit"),
10 EnumEntry::new("Timer", "Timer"),
11 EnumEntry::new("Install", "Install"),
12 EnumEntry::new("Mount", "Mount"),
13 EnumEntry::new("Service", "Service")]))
14 .schema();
15
16 pub const SYSTEMD_STRING_SCHEMA: Schema =
17 StringSchema::new("Systemd configuration value.")
18 .format(&SINGLE_LINE_COMMENT_FORMAT)
19 .schema();
20
21 pub const SYSTEMD_STRING_ARRAY_SCHEMA: Schema = ArraySchema::new(
22 "Array of Strings", &SYSTEMD_STRING_SCHEMA)
23 .schema();
24
25 pub const SYSTEMD_TIMESPAN_ARRAY_SCHEMA: Schema = ArraySchema::new(
26 "Array of time spans", &SYSTEMD_TIMESPAN_SCHEMA)
27 .schema();
28
29 pub const SYSTEMD_CALENDAR_EVENT_ARRAY_SCHEMA: Schema = ArraySchema::new(
30 "Array of calendar events", &SYSTEMD_CALENDAR_EVENT_SCHEMA)
31 .schema();
32
33 #[api(
34 properties: {
35 "OnCalendar": {
36 schema: SYSTEMD_CALENDAR_EVENT_ARRAY_SCHEMA,
37 optional: true,
38 },
39 "OnActiveSec": {
40 schema: SYSTEMD_TIMESPAN_ARRAY_SCHEMA,
41 optional: true,
42 },
43 "OnBootSec": {
44 schema: SYSTEMD_TIMESPAN_ARRAY_SCHEMA,
45 optional: true,
46 },
47 "OnStartupSec": {
48 schema: SYSTEMD_TIMESPAN_ARRAY_SCHEMA,
49 optional: true,
50 },
51 "OnUnitActiveSec": {
52 schema: SYSTEMD_TIMESPAN_ARRAY_SCHEMA,
53 optional: true,
54 },
55 "OnUnitInactiveSec": {
56 schema: SYSTEMD_TIMESPAN_ARRAY_SCHEMA,
57 optional: true,
58 },
59 "RandomizedDelaySec": {
60 schema: SYSTEMD_TIMESPAN_SCHEMA,
61 optional: true,
62 },
63 "AccuracySec": {
64 schema: SYSTEMD_TIMESPAN_SCHEMA,
65 optional: true,
66 },
67 },
68 )]
69 #[derive(Serialize, Deserialize, Default)]
70 #[allow(non_snake_case)]
71 /// Systemd Timer Section
72 pub struct SystemdTimerSection {
73 #[serde(skip_serializing_if="Option::is_none")]
74 pub OnCalendar: Option<Vec<String>>,
75 /// If true, the time when the service unit was last triggered is stored on disk.
76 #[serde(skip_serializing_if="Option::is_none")]
77 pub Persistent: Option<bool>,
78 #[serde(skip_serializing_if="Option::is_none")]
79 pub OnActiveSec: Option<Vec<String>>,
80 #[serde(skip_serializing_if="Option::is_none")]
81 pub OnBootSec: Option<Vec<String>>,
82 #[serde(skip_serializing_if="Option::is_none")]
83 pub OnStartupSec: Option<Vec<String>>,
84 #[serde(skip_serializing_if="Option::is_none")]
85 pub OnUnitActiveSec: Option<Vec<String>>,
86 #[serde(skip_serializing_if="Option::is_none")]
87 pub OnUnitInactiveSec: Option<Vec<String>>,
88 #[serde(skip_serializing_if="Option::is_none")]
89 pub RandomizedDelaySec: Option<String>,
90 #[serde(skip_serializing_if="Option::is_none")]
91 pub AccuracySec: Option<String>,
92
93 /// Trigger when system clock jumps.
94 #[serde(skip_serializing_if="Option::is_none")]
95 pub OnClockChange: Option<bool>,
96
97 /// Trigger when time zone changes.
98 #[serde(skip_serializing_if="Option::is_none")]
99 pub OnTimezomeChange: Option<bool>,
100
101 /// The unit to activate when this timer elapses.
102 #[serde(skip_serializing_if="Option::is_none")]
103 pub Unit: Option<String>,
104
105 /// If true, an elapsing timer will cause the system to resume from suspend.
106 #[serde(skip_serializing_if="Option::is_none")]
107 pub WakeSystem: Option<bool>,
108
109 /// If true, an elapsed timer will stay loaded, and its state remains queryable.
110 #[serde(skip_serializing_if="Option::is_none")]
111 pub RemainAfterElapse: Option<bool>,
112 }
113
114 #[api(
115 properties: {
116 "Type": {
117 type: ServiceStartup,
118 optional: true,
119 },
120 "ExecStart": {
121 schema: SYSTEMD_STRING_ARRAY_SCHEMA,
122 optional: true,
123 },
124 }
125 )]
126 #[derive(Serialize, Deserialize, Default)]
127 #[allow(non_snake_case)]
128 /// Systemd Service Section
129 pub struct SystemdServiceSection {
130 /// The process start-up type for this service unit.
131 #[serde(skip_serializing_if="Option::is_none")]
132 pub Type: Option<ServiceStartup>,
133 #[serde(skip_serializing_if="Option::is_none")]
134 pub ExecStart: Option<Vec<String>>,
135 }
136
137 #[api()]
138 #[derive(Serialize, Deserialize, Default)]
139 #[allow(non_snake_case)]
140 /// Systemd Unit Section
141 pub struct SystemdUnitSection {
142 /// A human readable name for the unit.
143 pub Description: String,
144 /// Check whether the system has AC power.
145 #[serde(skip_serializing_if="Option::is_none")]
146 pub ConditionACPower: Option<bool>,
147 }
148
149 #[api(
150 properties: {
151 "Alias": {
152 schema: SYSTEMD_STRING_ARRAY_SCHEMA,
153 optional: true,
154 },
155 "Also": {
156 schema: SYSTEMD_STRING_ARRAY_SCHEMA,
157 optional: true,
158 },
159 "DefaultInstance": {
160 optional: true,
161 },
162 "WantedBy": {
163 schema: SYSTEMD_STRING_ARRAY_SCHEMA,
164 optional: true,
165 },
166 "RequiredBy": {
167 schema: SYSTEMD_STRING_ARRAY_SCHEMA,
168 optional: true,
169 },
170 },
171 )]
172 #[derive(Serialize, Deserialize, Default)]
173 #[allow(non_snake_case)]
174 /// Systemd Install Section
175 pub struct SystemdInstallSection {
176 #[serde(skip_serializing_if="Option::is_none")]
177 pub Alias: Option<Vec<String>>,
178 #[serde(skip_serializing_if="Option::is_none")]
179 pub Also: Option<Vec<String>>,
180 /// DefaultInstance for template unit.
181 #[serde(skip_serializing_if="Option::is_none")]
182 pub DefaultInstance: Option<String>,
183 #[serde(skip_serializing_if="Option::is_none")]
184 pub WantedBy: Option<Vec<String>>,
185 #[serde(skip_serializing_if="Option::is_none")]
186 pub RequiredBy: Option<Vec<String>>,
187 }
188
189 #[api(
190 properties: {
191 "TimeoutSec": {
192 schema: SYSTEMD_TIMESPAN_ARRAY_SCHEMA,
193 optional: true,
194 },
195 }
196 )]
197 #[derive(Serialize, Deserialize, Default)]
198 #[allow(non_snake_case)]
199 /// Systemd Service Section
200 pub struct SystemdMountSection {
201 /// absolute path of a device node, file or other resource to mount
202 pub What: String,
203 /// absolute path of a file or directory for the mount point
204 pub Where: String,
205 /// Takes a string for the file system type. See mount(8) for details.
206 #[serde(skip_serializing_if="Option::is_none")]
207 pub Type: Option<String>,
208 /// Mount options to use when mounting. This takes a comma-separated list of options.
209 #[serde(skip_serializing_if="Option::is_none")]
210 pub Options: Option<String>,
211 /// If true, parsing of the options specified in Options= is relaxed, and unknown mount options are tolerated.
212 #[serde(skip_serializing_if="Option::is_none")]
213 pub SloppyOptions: Option<bool>,
214 /// Use lazy unmount
215 #[serde(skip_serializing_if="Option::is_none")]
216 pub LazyUnmount: Option<bool>,
217 /// Use forces unmount
218 #[serde(skip_serializing_if="Option::is_none")]
219 pub ForceUnmount: Option<bool>,
220 /// Directories of mount points (and any parent directories) are
221 /// automatically created if needed. Takes an access mode in octal
222 /// notation. Defaults to 0755.
223 #[serde(skip_serializing_if="Option::is_none")]
224 pub DirectoryMode: Option<String>,
225 /// Configures the time to wait for the mount command to finish.
226 #[serde(skip_serializing_if="Option::is_none")]
227 pub TimeoutSec: Option<String>,
228 }
229
230 #[api()]
231 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
232 #[serde(rename_all = "lowercase")]
233 /// Node Power command type.
234 pub enum ServiceStartup {
235 /// Simple fork
236 Simple,
237 /// Like fork, but wait until exec succeeds
238 Exec,
239 /// Fork daemon
240 Forking,
241 /// Like 'simple', but consider the unit up after the process exits.
242 Oneshot,
243 /// Like 'simple', but use DBUS to synchronize startup.
244 Dbus,
245 /// Like 'simple', but use sd_notify to synchronize startup.
246 Notify,
247 }
248
249 pub const SYSTEMD_TIMESPAN_SCHEMA: Schema = StringSchema::new(
250 "systemd time span")
251 .format(&ApiStringFormat::VerifyFn(proxmox_systemd::time::verify_time_span))
252 .schema();
253
254 pub const SYSTEMD_CALENDAR_EVENT_SCHEMA: Schema = StringSchema::new(
255 "systemd calendar event")
256 .format(&ApiStringFormat::VerifyFn(proxmox_systemd::time::verify_calendar_event))
257 .schema();