Skip to main content

devops_armory/ini_parser/
parser.rs

1use std::path::Path;
2
3use ini::Ini;
4
5/// INI file creator based on provided parameters
6/// Can be used in SystemD OS, like Ubuntu or Debian
7pub fn ini_parser(
8    section_unit: &str,
9    description: &str,
10    after: &str,
11    section_service: &str,
12    environment: &str,
13    r#type: &str,
14    user: &str,
15    working_directory: &str,
16    exec_start: &str,
17    restart: &str,
18    restart_delay: &str,
19    std_out: &str,
20    std_err: &str,
21    section_install: &str,
22    wanted_by: &str,
23    filename: &Path
24) {
25    // Init INI formatter
26    let mut conf = Ini::new();
27
28    conf.with_section(Some(section_unit))
29        .set("Description", description)
30        .set("After", after);
31    conf.with_section(Some(section_service))
32        .set("Environment", environment)
33        .set("Type", r#type)
34        .set("User", user)
35        .set("WorkingDirectory", working_directory)
36        .set("ExecStart", exec_start)
37        .set("Restart", restart)
38        .set("RestartSec", restart_delay)
39        .set("StandardOutput", std_out)
40        .set("StandardError", std_err);
41    conf.with_section(Some(section_install))
42        .set("WantedBy", wanted_by);
43    conf.write_to_file(filename).unwrap();
44
45}