From bf7ea56ed18b1b3bedad68d58e1c1f6b2387a5a6 Mon Sep 17 00:00:00 2001 From: Ben Cressey Date: Fri, 8 Jul 2022 19:48:33 +0000 Subject: [PATCH 1/2] models: fix affected services for ntp Since the service is named "ntp" rather than "chronyd", the restart commands were not run when NTP settings changed. Signed-off-by: Ben Cressey --- sources/models/shared-defaults/defaults.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/models/shared-defaults/defaults.toml b/sources/models/shared-defaults/defaults.toml index 1bf9942cdcb..6354703d842 100644 --- a/sources/models/shared-defaults/defaults.toml +++ b/sources/models/shared-defaults/defaults.toml @@ -117,7 +117,7 @@ path = "/etc/chrony.conf" template-path = "/usr/share/templates/chrony-conf" [metadata.settings.ntp] -affected-services = ["chronyd"] +affected-services = ["ntp"] # Kernel From 5431a768ddf9e90f981ddc86ecf84d4b693638de Mon Sep 17 00:00:00 2001 From: Ben Cressey Date: Fri, 8 Jul 2022 19:47:57 +0000 Subject: [PATCH 2/2] migrations: fix affected services for ntp Ensure that existing hosts get the fix to properly restart the NTP service on upgrade. Signed-off-by: Ben Cressey --- Release.toml | 3 ++ sources/Cargo.lock | 7 +++++ sources/Cargo.toml | 1 + .../v1.9.0/ntp-affected-services/Cargo.toml | 12 ++++++++ .../v1.9.0/ntp-affected-services/src/main.rs | 30 +++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 sources/api/migration/migrations/v1.9.0/ntp-affected-services/Cargo.toml create mode 100644 sources/api/migration/migrations/v1.9.0/ntp-affected-services/src/main.rs diff --git a/Release.toml b/Release.toml index 8356360294b..ad265b852f7 100644 --- a/Release.toml +++ b/Release.toml @@ -130,3 +130,6 @@ version = "1.8.0" "migrate_v1.8.0_public-admin-container-v0-9-0.lz4", "migrate_v1.8.0_public-control-container-v0-6-1.lz4", ] +"(1.8.0, 1.9.0)" = [ + "migrate_v1.9.0_ntp-affected-services.lz4", +] diff --git a/sources/Cargo.lock b/sources/Cargo.lock index 4dc4a5c7141..0031b829c08 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -2180,6 +2180,13 @@ dependencies = [ "winapi", ] +[[package]] +name = "ntp-affected-services" +version = "0.1.0" +dependencies = [ + "migration-helpers", +] + [[package]] name = "num" version = "0.4.0" diff --git a/sources/Cargo.toml b/sources/Cargo.toml index bd65be2aab1..a28bd803f5f 100644 --- a/sources/Cargo.toml +++ b/sources/Cargo.toml @@ -61,6 +61,7 @@ members = [ "api/migration/migrations/v1.8.0/aws-control-container-v0-6-1", "api/migration/migrations/v1.8.0/public-admin-container-v0-9-0", "api/migration/migrations/v1.8.0/public-control-container-v0-6-1", + "api/migration/migrations/v1.9.0/ntp-affected-services", "bottlerocket-release", diff --git a/sources/api/migration/migrations/v1.9.0/ntp-affected-services/Cargo.toml b/sources/api/migration/migrations/v1.9.0/ntp-affected-services/Cargo.toml new file mode 100644 index 00000000000..f286f59ac56 --- /dev/null +++ b/sources/api/migration/migrations/v1.9.0/ntp-affected-services/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "ntp-affected-services" +version = "0.1.0" +authors = ["Ben Cressey "] +license = "Apache-2.0 OR MIT" +edition = "2018" +publish = false +# Don't rebuild crate just because of changes to README. +exclude = ["README.md"] + +[dependencies] +migration-helpers = { path = "../../../migration-helpers", version = "0.1.0" } diff --git a/sources/api/migration/migrations/v1.9.0/ntp-affected-services/src/main.rs b/sources/api/migration/migrations/v1.9.0/ntp-affected-services/src/main.rs new file mode 100644 index 00000000000..b9fd3d0b84d --- /dev/null +++ b/sources/api/migration/migrations/v1.9.0/ntp-affected-services/src/main.rs @@ -0,0 +1,30 @@ +#![deny(rust_2018_idioms)] + +use migration_helpers::common_migrations::{ + MetadataListReplacement, ReplaceMetadataListsMigration, +}; +use migration_helpers::{migrate, Result}; +use std::process; + +/// We updated the 'affected-services' list metadata for 'settings.ntp' to refer +/// to the correct service name ("ntp") instead of the incorrect one ("chronyd"). +fn run() -> Result<()> { + migrate(ReplaceMetadataListsMigration(vec![ + MetadataListReplacement { + setting: "settings.ntp", + metadata: "affected-services", + old_vals: &["chronyd"], + new_vals: &["ntp"], + }, + ])) +} + +// Returning a Result from main makes it print a Debug representation of the error, but with Snafu +// we have nice Display representations of the error, so we wrap "main" (run) and print any error. +// https://github.com/shepmaster/snafu/issues/110 +fn main() { + if let Err(e) = run() { + eprintln!("{}", e); + process::exit(1); + } +}