proxmox-systemd: remove crate, use new proxmox-time 1.1.0 instead
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
@ -187,9 +187,9 @@ pub fn create_datastore_disk(
|
||||
|
||||
let mount_unit_name = create_datastore_mount_unit(&name, &mount_point, filesystem, &uuid_path)?;
|
||||
|
||||
proxmox_systemd::reload_daemon()?;
|
||||
proxmox_systemd::enable_unit(&mount_unit_name)?;
|
||||
proxmox_systemd::start_unit(&mount_unit_name)?;
|
||||
crate::tools::systemd::reload_daemon()?;
|
||||
crate::tools::systemd::enable_unit(&mount_unit_name)?;
|
||||
crate::tools::systemd::start_unit(&mount_unit_name)?;
|
||||
|
||||
if add_datastore {
|
||||
let lock = pbs_config::datastore::lock_config()?;
|
||||
@ -245,7 +245,7 @@ pub fn delete_datastore_disk(name: String) -> Result<(), Error> {
|
||||
// disable systemd mount-unit
|
||||
let mut mount_unit_name = proxmox::tools::systemd::escape_unit(&path, true);
|
||||
mount_unit_name.push_str(".mount");
|
||||
proxmox_systemd::disable_unit(&mount_unit_name)?;
|
||||
crate::tools::systemd::disable_unit(&mount_unit_name)?;
|
||||
|
||||
// delete .mount-file
|
||||
let mount_unit_path = format!("/etc/systemd/system/{}", mount_unit_name);
|
||||
|
@ -270,7 +270,7 @@ pub fn create_zpool(
|
||||
|
||||
if std::path::Path::new("/lib/systemd/system/zfs-import@.service").exists() {
|
||||
let import_unit = format!("zfs-import@{}.service", proxmox::tools::systemd::escape_unit(&name, false));
|
||||
proxmox_systemd::enable_unit(&import_unit)?;
|
||||
crate::tools::systemd::enable_unit(&import_unit)?;
|
||||
}
|
||||
|
||||
if let Some(compression) = compression {
|
||||
|
@ -46,7 +46,7 @@ use proxmox_backup::{
|
||||
};
|
||||
|
||||
use pbs_buildcfg::configdir;
|
||||
use proxmox_systemd::time::{compute_next_event, parse_calendar_event};
|
||||
use proxmox_time::{compute_next_event, parse_calendar_event};
|
||||
use pbs_tools::logrotate::LogRotate;
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -11,8 +11,7 @@ use cidr::IpInet;
|
||||
use proxmox_http::client::{ShareableRateLimit, RateLimiter};
|
||||
use proxmox_section_config::SectionConfigData;
|
||||
|
||||
use proxmox_systemd::daily_duration::{parse_daily_duration, DailyDuration};
|
||||
use proxmox_time::TmEditor;
|
||||
use proxmox_time::{parse_daily_duration, DailyDuration, TmEditor};
|
||||
|
||||
use pbs_api_types::TrafficControlRule;
|
||||
|
||||
|
@ -431,7 +431,7 @@ pub fn send_tape_backup_status(
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let (fqdn, port) = get_server_url();
|
||||
let duration: proxmox_systemd::time::TimeSpan = summary.duration.into();
|
||||
let duration: proxmox_time::TimeSpan = summary.duration.into();
|
||||
let mut data = json!({
|
||||
"job": job,
|
||||
"fqdn": fqdn,
|
||||
|
@ -46,7 +46,7 @@ use proxmox::tools::fs::{
|
||||
create_path, file_read_optional_string, replace_file, CreateOptions,
|
||||
};
|
||||
|
||||
use proxmox_systemd::time::{compute_next_event, parse_calendar_event};
|
||||
use proxmox_time::{compute_next_event, parse_calendar_event};
|
||||
|
||||
use pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR_M;
|
||||
use pbs_config::{open_backup_lockfile, BackupLockGuard};
|
||||
|
@ -33,7 +33,7 @@ use serde_json::json;
|
||||
use proxmox::tools::fs::{replace_file, file_get_json, CreateOptions};
|
||||
use proxmox_uuid::Uuid;
|
||||
|
||||
use proxmox_systemd::time::compute_next_event;
|
||||
use proxmox_time::compute_next_event;
|
||||
use pbs_config::BackupLockGuard;
|
||||
use pbs_api_types::{MediaSetPolicy, RetentionPolicy, MediaStatus, MediaLocation};
|
||||
|
||||
|
@ -18,7 +18,7 @@ use pbs_api_types::{
|
||||
Fingerprint, MediaStatus, MediaLocation, MediaSetPolicy, RetentionPolicy,
|
||||
MediaPoolConfig,
|
||||
};
|
||||
use proxmox_systemd::time::compute_next_event;
|
||||
use proxmox_time::compute_next_event;
|
||||
use pbs_config::BackupLockGuard;
|
||||
|
||||
use crate::tape::{
|
||||
|
@ -5,7 +5,7 @@
|
||||
use std::path::PathBuf;
|
||||
use anyhow::Error;
|
||||
|
||||
use proxmox_systemd::time::parse_time_span;
|
||||
use proxmox_time::parse_time_span;
|
||||
use pbs_api_types::{RetentionPolicy, MediaSetPolicy};
|
||||
|
||||
use crate::tape::{Inventory, MediaPool};
|
||||
|
@ -100,8 +100,8 @@ fn test_media_expire_time() -> Result<(), Error> {
|
||||
let sl2= MediaSetLabel::with_data("p1", Uuid::generate(), 0, ctime + 120, None);
|
||||
let tape2_uuid = inventory.generate_used_tape("tape2", sl2, 0);
|
||||
|
||||
let event = proxmox_systemd::time::parse_calendar_event("*:0/2")?;
|
||||
let span = proxmox_systemd::time::parse_time_span("120 seconds")?;
|
||||
let event = proxmox_time::parse_calendar_event("*:0/2")?;
|
||||
let span = proxmox_time::parse_time_span("120 seconds")?;
|
||||
|
||||
let pool = MediaPool::new(
|
||||
"p1",
|
||||
|
@ -1,2 +1,5 @@
|
||||
pub mod config;
|
||||
pub mod types;
|
||||
|
||||
mod unit;
|
||||
pub use unit::*;
|
||||
|
@ -248,10 +248,10 @@ pub enum ServiceStartup {
|
||||
|
||||
pub const SYSTEMD_TIMESPAN_SCHEMA: Schema = StringSchema::new(
|
||||
"systemd time span")
|
||||
.format(&ApiStringFormat::VerifyFn(proxmox_systemd::time::verify_time_span))
|
||||
.format(&ApiStringFormat::VerifyFn(proxmox_time::verify_time_span))
|
||||
.schema();
|
||||
|
||||
pub const SYSTEMD_CALENDAR_EVENT_SCHEMA: Schema = StringSchema::new(
|
||||
"systemd calendar event")
|
||||
.format(&ApiStringFormat::VerifyFn(proxmox_systemd::time::verify_calendar_event))
|
||||
.format(&ApiStringFormat::VerifyFn(proxmox_time::verify_calendar_event))
|
||||
.schema();
|
||||
|
127
src/tools/systemd/unit.rs
Normal file
127
src/tools/systemd/unit.rs
Normal file
@ -0,0 +1,127 @@
|
||||
use std::process::Command;
|
||||
|
||||
use anyhow::{bail, format_err, Error};
|
||||
|
||||
fn run_command(mut command: Command) -> Result<(), Error> {
|
||||
let output = command
|
||||
.output()
|
||||
.map_err(|err| format_err!("failed to execute {:?} - {}", command, err))?;
|
||||
|
||||
proxmox_lang::try_block!({
|
||||
if !output.status.success() {
|
||||
match output.status.code() {
|
||||
Some(code) => {
|
||||
if code != 0 {
|
||||
let msg = String::from_utf8(output.stderr)
|
||||
.map(|m| {
|
||||
if m.is_empty() {
|
||||
String::from("no error message")
|
||||
} else {
|
||||
m
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|_| String::from("non utf8 error message (suppressed)"));
|
||||
|
||||
bail!("status code: {} - {}", code, msg);
|
||||
}
|
||||
}
|
||||
None => bail!("terminated by signal"),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}).map_err(|err| format_err!("command {:?} failed - {}", command, err))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reload_daemon() -> Result<(), Error> {
|
||||
let mut command = std::process::Command::new("systemctl");
|
||||
command.arg("daemon-reload");
|
||||
|
||||
run_command(command)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn disable_unit(unit: &str) -> Result<(), Error> {
|
||||
let mut command = std::process::Command::new("systemctl");
|
||||
command.arg("disable");
|
||||
command.arg(unit);
|
||||
|
||||
run_command(command)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn enable_unit(unit: &str) -> Result<(), Error> {
|
||||
let mut command = std::process::Command::new("systemctl");
|
||||
command.arg("enable");
|
||||
command.arg(unit);
|
||||
|
||||
run_command(command)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn start_unit(unit: &str) -> Result<(), Error> {
|
||||
let mut command = std::process::Command::new("systemctl");
|
||||
command.arg("start");
|
||||
command.arg(unit);
|
||||
|
||||
run_command(command)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn stop_unit(unit: &str) -> Result<(), Error> {
|
||||
let mut command = std::process::Command::new("systemctl");
|
||||
command.arg("stop");
|
||||
command.arg(unit);
|
||||
|
||||
run_command(command)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reload_unit(unit: &str) -> Result<(), Error> {
|
||||
let mut command = std::process::Command::new("systemctl");
|
||||
command.arg("try-reload-or-restart");
|
||||
command.arg(unit);
|
||||
|
||||
run_command(command)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_unit() -> Result<(), Error> {
|
||||
fn test_escape(i: &str, expected: &str, is_path: bool) {
|
||||
|
||||
use proxmox::tools::systemd::{escape_unit, unescape_unit};
|
||||
|
||||
let escaped = escape_unit(i, is_path);
|
||||
assert_eq!(escaped, expected);
|
||||
let unescaped = unescape_unit(&escaped).unwrap();
|
||||
if is_path {
|
||||
let mut p = i.trim_matches('/');
|
||||
if p.is_empty() {
|
||||
p = "/";
|
||||
}
|
||||
assert_eq!(p, unescaped);
|
||||
} else {
|
||||
assert_eq!(i, unescaped);
|
||||
}
|
||||
}
|
||||
|
||||
test_escape(".test", "\\x2etest", false);
|
||||
test_escape("t.est", "t.est", false);
|
||||
test_escape("_test_", "_test_", false);
|
||||
|
||||
test_escape("/", "-", false);
|
||||
test_escape("//", "--", false);
|
||||
|
||||
test_escape("/", "-", true);
|
||||
test_escape("//", "-", true);
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user