]> git.proxmox.com Git - proxmox-backup.git/commitdiff
renamed: src/tools/systemd/parser.rs -> src/tools/systemd/config.rs
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 16 May 2020 04:32:28 +0000 (06:32 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 16 May 2020 04:32:28 +0000 (06:32 +0200)
src/config/jobs.rs
src/tools/systemd.rs
src/tools/systemd/config.rs [new file with mode: 0644]
src/tools/systemd/parser.rs [deleted file]

index f381a1012c96207e83c6db5096dcd3bebd5bb1c5..129cf22f10f29978e0212d3551d74703e387bcb0 100644 (file)
@@ -5,7 +5,7 @@ use lazy_static::lazy_static;
 use proxmox::api::section_config::SectionConfigData;
 
 use crate::PROXMOX_SAFE_ID_REGEX_STR;
-use crate::tools::systemd::parser::*;
+use crate::tools::systemd::config::*;
 use crate::tools::systemd::types::*;
 
 const SYSTEMD_CONFIG_DIR: &str = "/etc/systemd/system";
index 5f97848df82df01a626a438e8955abd86a4de4b9..49c909d44a922fba25795792111656bb6527023b 100644 (file)
@@ -1,3 +1,3 @@
 pub mod time;
 pub mod types;
-pub mod parser;
+pub mod config;
diff --git a/src/tools/systemd/config.rs b/src/tools/systemd/config.rs
new file mode 100644 (file)
index 0000000..cc5ad69
--- /dev/null
@@ -0,0 +1,119 @@
+use anyhow::Error;
+use lazy_static::lazy_static;
+
+use super::types::*;
+
+use proxmox::api::{
+    schema::*,
+    section_config::{
+        SectionConfig,
+        SectionConfigData,
+        SectionConfigPlugin,
+    }
+};
+
+use proxmox::tools::{fs::replace_file, fs::CreateOptions};
+
+
+lazy_static! {
+    pub static ref SERVICE_CONFIG: SectionConfig = init_service();
+    pub static ref TIMER_CONFIG: SectionConfig = init_timer();
+}
+
+fn init_service() -> SectionConfig {
+
+    let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA);
+
+    match SystemdUnitSection::API_SCHEMA {
+        Schema::Object(ref obj_schema) =>  {
+            let plugin = SectionConfigPlugin::new("Unit".to_string(), obj_schema);
+            config.register_plugin(plugin);
+        }
+        _ => unreachable!(),
+    };
+    match SystemdInstallSection::API_SCHEMA {
+        Schema::Object(ref obj_schema) =>  {
+            let plugin = SectionConfigPlugin::new("Install".to_string(), obj_schema);
+            config.register_plugin(plugin);
+        }
+        _ => unreachable!(),
+    };
+    match SystemdServiceSection::API_SCHEMA {
+        Schema::Object(ref obj_schema) =>  {
+            let plugin = SectionConfigPlugin::new("Service".to_string(), obj_schema);
+            config.register_plugin(plugin);
+        }
+        _ => unreachable!(),
+    };
+
+    config
+}
+
+fn init_timer() -> SectionConfig {
+
+    let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA);
+
+    match SystemdUnitSection::API_SCHEMA {
+        Schema::Object(ref obj_schema) =>  {
+            let plugin = SectionConfigPlugin::new("Unit".to_string(), obj_schema);
+            config.register_plugin(plugin);
+        }
+        _ => unreachable!(),
+    };
+    match SystemdInstallSection::API_SCHEMA {
+        Schema::Object(ref obj_schema) =>  {
+            let plugin = SectionConfigPlugin::new("Install".to_string(), obj_schema);
+            config.register_plugin(plugin);
+        }
+        _ => unreachable!(),
+    };
+    match SystemdTimerSection::API_SCHEMA {
+        Schema::Object(ref obj_schema) =>  {
+            let plugin = SectionConfigPlugin::new("Timer".to_string(), obj_schema);
+            config.register_plugin(plugin);
+        }
+        _ => unreachable!(),
+    };
+
+    config
+}
+
+fn parse_systemd_config(config: &SectionConfig, filename: &str) -> Result<SectionConfigData, Error> {
+
+    let raw = proxmox::tools::fs::file_get_contents(filename)?;
+    let input = String::from_utf8(raw)?;
+
+    let data = config.parse(filename, &input)?;
+
+    Ok(data)
+}
+
+pub fn parse_systemd_service(filename: &str) -> Result<SectionConfigData, Error> {
+    parse_systemd_config(&SERVICE_CONFIG, filename)
+}
+
+pub fn parse_systemd_timer(filename: &str) -> Result<SectionConfigData, Error> {
+    parse_systemd_config(&TIMER_CONFIG, filename)
+}
+
+fn save_systemd_config(config: &SectionConfig, filename: &str, data: &SectionConfigData) -> Result<(), Error> {
+    let raw = config.write(filename, &data)?;
+
+    let mode = nix::sys::stat::Mode::from_bits_truncate(0o0644);
+    // set the correct owner/group/permissions while saving file, owner(rw) = root
+    let options = CreateOptions::new()
+        .perm(mode)
+        .owner(nix::unistd::ROOT);
+
+    replace_file(filename, raw.as_bytes(), options)?;
+
+    Ok(())
+}
+
+pub fn save_systemd_service(filename: &str, data: &SectionConfigData) -> Result<(), Error> {
+    save_systemd_config(&SERVICE_CONFIG, filename, data)
+}
+
+pub fn save_systemd_timer(filename: &str, data: &SectionConfigData) -> Result<(), Error> {
+    save_systemd_config(&TIMER_CONFIG, filename, data)
+}
diff --git a/src/tools/systemd/parser.rs b/src/tools/systemd/parser.rs
deleted file mode 100644 (file)
index cc5ad69..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-use anyhow::Error;
-use lazy_static::lazy_static;
-
-use super::types::*;
-
-use proxmox::api::{
-    schema::*,
-    section_config::{
-        SectionConfig,
-        SectionConfigData,
-        SectionConfigPlugin,
-    }
-};
-
-use proxmox::tools::{fs::replace_file, fs::CreateOptions};
-
-
-lazy_static! {
-    pub static ref SERVICE_CONFIG: SectionConfig = init_service();
-    pub static ref TIMER_CONFIG: SectionConfig = init_timer();
-}
-
-fn init_service() -> SectionConfig {
-
-    let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA);
-
-    match SystemdUnitSection::API_SCHEMA {
-        Schema::Object(ref obj_schema) =>  {
-            let plugin = SectionConfigPlugin::new("Unit".to_string(), obj_schema);
-            config.register_plugin(plugin);
-        }
-        _ => unreachable!(),
-    };
-    match SystemdInstallSection::API_SCHEMA {
-        Schema::Object(ref obj_schema) =>  {
-            let plugin = SectionConfigPlugin::new("Install".to_string(), obj_schema);
-            config.register_plugin(plugin);
-        }
-        _ => unreachable!(),
-    };
-    match SystemdServiceSection::API_SCHEMA {
-        Schema::Object(ref obj_schema) =>  {
-            let plugin = SectionConfigPlugin::new("Service".to_string(), obj_schema);
-            config.register_plugin(plugin);
-        }
-        _ => unreachable!(),
-    };
-
-    config
-}
-
-fn init_timer() -> SectionConfig {
-
-    let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA);
-
-    match SystemdUnitSection::API_SCHEMA {
-        Schema::Object(ref obj_schema) =>  {
-            let plugin = SectionConfigPlugin::new("Unit".to_string(), obj_schema);
-            config.register_plugin(plugin);
-        }
-        _ => unreachable!(),
-    };
-    match SystemdInstallSection::API_SCHEMA {
-        Schema::Object(ref obj_schema) =>  {
-            let plugin = SectionConfigPlugin::new("Install".to_string(), obj_schema);
-            config.register_plugin(plugin);
-        }
-        _ => unreachable!(),
-    };
-    match SystemdTimerSection::API_SCHEMA {
-        Schema::Object(ref obj_schema) =>  {
-            let plugin = SectionConfigPlugin::new("Timer".to_string(), obj_schema);
-            config.register_plugin(plugin);
-        }
-        _ => unreachable!(),
-    };
-
-    config
-}
-
-fn parse_systemd_config(config: &SectionConfig, filename: &str) -> Result<SectionConfigData, Error> {
-
-    let raw = proxmox::tools::fs::file_get_contents(filename)?;
-    let input = String::from_utf8(raw)?;
-
-    let data = config.parse(filename, &input)?;
-
-    Ok(data)
-}
-
-pub fn parse_systemd_service(filename: &str) -> Result<SectionConfigData, Error> {
-    parse_systemd_config(&SERVICE_CONFIG, filename)
-}
-
-pub fn parse_systemd_timer(filename: &str) -> Result<SectionConfigData, Error> {
-    parse_systemd_config(&TIMER_CONFIG, filename)
-}
-
-fn save_systemd_config(config: &SectionConfig, filename: &str, data: &SectionConfigData) -> Result<(), Error> {
-    let raw = config.write(filename, &data)?;
-
-    let mode = nix::sys::stat::Mode::from_bits_truncate(0o0644);
-    // set the correct owner/group/permissions while saving file, owner(rw) = root
-    let options = CreateOptions::new()
-        .perm(mode)
-        .owner(nix::unistd::ROOT);
-
-    replace_file(filename, raw.as_bytes(), options)?;
-
-    Ok(())
-}
-
-pub fn save_systemd_service(filename: &str, data: &SectionConfigData) -> Result<(), Error> {
-    save_systemd_config(&SERVICE_CONFIG, filename, data)
-}
-
-pub fn save_systemd_timer(filename: &str, data: &SectionConfigData) -> Result<(), Error> {
-    save_systemd_config(&TIMER_CONFIG, filename, data)
-}