switch-to-configuration-ng: Reload when ExecReload changes
Instead of triggering a restart when the reload script changes, signal that the unit only needs to be reloaded instead. This is an important optimisation for systemd-nspawn containers where the reload script can house the container's config activation script and we want to explicitly avoid restarting.
This commit is contained in:
@@ -576,6 +576,12 @@ fn compare_units(current_unit: &UnitInfo, new_unit: &UnitInfo) -> UnitComparison
|
||||
}
|
||||
}
|
||||
|
||||
// If this is a service unit, check if it was only `ExecReload`
|
||||
if section_name == "Service" && ini_key == "ExecReload" {
|
||||
ret = UnitComparison::UnequalNeedsReload;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this is a mount unit, check if it was only `Options`
|
||||
if section_name == "Mount" && ini_key == "Options" {
|
||||
ret = UnitComparison::UnequalNeedsReload;
|
||||
@@ -598,6 +604,10 @@ fn compare_units(current_unit: &UnitInfo, new_unit: &UnitInfo) -> UnitComparison
|
||||
return UnitComparison::UnequalNeedsRestart;
|
||||
}
|
||||
}
|
||||
} else if section_name == "Exec" && ini_cmp.len() == 1
|
||||
&& ini_cmp.contains_key("ExecReload") {
|
||||
ret = UnitComparison::UnequalNeedsReload;
|
||||
continue;
|
||||
} else {
|
||||
return UnitComparison::UnequalNeedsRestart;
|
||||
}
|
||||
@@ -606,7 +616,7 @@ fn compare_units(current_unit: &UnitInfo, new_unit: &UnitInfo) -> UnitComparison
|
||||
|
||||
// A section was introduced that was missing in the previous unit
|
||||
if !section_cmp.is_empty() {
|
||||
if section_cmp.keys().len() == 1 && section_cmp.contains_key("Unit") {
|
||||
if section_cmp.keys().len() == 1 && (section_cmp.contains_key("Unit") || section_cmp.contains_key("Service")) {
|
||||
if let Some(new_unit_unit) = new_unit.get("Unit") {
|
||||
for ini_key in new_unit_unit.keys() {
|
||||
if !unit_section_ignores.contains_key(ini_key.as_str()) {
|
||||
@@ -615,6 +625,14 @@ fn compare_units(current_unit: &UnitInfo, new_unit: &UnitInfo) -> UnitComparison
|
||||
ret = UnitComparison::UnequalNeedsReload;
|
||||
}
|
||||
}
|
||||
} else if let Some(new_unit_service) = new_unit.get("Service") {
|
||||
if new_unit_service.len() == 1 && new_unit_service.contains_key("ExecReload") {
|
||||
ret = UnitComparison::UnequalNeedsReload;
|
||||
} else {
|
||||
return UnitComparison::UnequalNeedsRestart;
|
||||
}
|
||||
} else {
|
||||
return UnitComparison::UnequalNeedsRestart;
|
||||
}
|
||||
} else {
|
||||
return UnitComparison::UnequalNeedsRestart;
|
||||
@@ -2623,6 +2641,38 @@ invalid
|
||||
) == super::UnitComparison::UnequalNeedsReload
|
||||
);
|
||||
|
||||
assert!(
|
||||
super::compare_units(
|
||||
&HashMap::from([]),
|
||||
&HashMap::from([(
|
||||
"Service".to_string(),
|
||||
HashMap::from([(
|
||||
"ExecReload".to_string(),
|
||||
vec!["foobar".to_string()]
|
||||
)])
|
||||
)])
|
||||
) == super::UnitComparison::UnequalNeedsReload
|
||||
);
|
||||
|
||||
assert!(
|
||||
super::compare_units(
|
||||
&HashMap::from([(
|
||||
"Service".to_string(),
|
||||
HashMap::from([(
|
||||
"ExecReload".to_string(),
|
||||
vec!["foobar".to_string()]
|
||||
)])
|
||||
)]),
|
||||
&HashMap::from([(
|
||||
"Service".to_string(),
|
||||
HashMap::from([(
|
||||
"ExecReload".to_string(),
|
||||
vec!["barfoo".to_string()]
|
||||
)])
|
||||
)])
|
||||
) == super::UnitComparison::UnequalNeedsReload
|
||||
);
|
||||
|
||||
assert!(
|
||||
super::compare_units(
|
||||
&HashMap::from([(
|
||||
|
||||
Reference in New Issue
Block a user