From b1fd5767317b5e15bf5a6fbb5a2240fe790ab177 Mon Sep 17 00:00:00 2001 From: Ian Littman Date: Thu, 27 Mar 2025 16:06:34 -0500 Subject: [PATCH] Ensure maintained apps are pulled immediately on next server start after FMAv2/WinFMA upgrade (#27589) For #27582. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [x] Manual QA for all new/changed functionality - [x] For unreleased bug fixes in a release candidate, confirmed that the fix is not expected to adversely impact load test results or alerted the release DRI if additional load testing is needed. --- .../mysql/migrations/tables/20250320200000_FMAv2.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/datastore/mysql/migrations/tables/20250320200000_FMAv2.go b/server/datastore/mysql/migrations/tables/20250320200000_FMAv2.go index e047e10368..5d057312eb 100644 --- a/server/datastore/mysql/migrations/tables/20250320200000_FMAv2.go +++ b/server/datastore/mysql/migrations/tables/20250320200000_FMAv2.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" + "github.com/fleetdm/fleet/v4/server/fleet" "github.com/jmoiron/sqlx" ) @@ -109,6 +110,13 @@ ALTER TABLE fleet_maintained_apps return fmt.Errorf("failed to rename Zoom FMA: %w", err) } + // Clear out scheduled runs for the maintained_apps cron. This will force the cron to run on + // next server start and sync the full maintained apps list, including Windows titles. + _, err = tx.Exec(`DELETE FROM cron_stats WHERE name = ? AND stats_type = ?`, fleet.CronMaintainedApps, fleet.CronStatsTypeScheduled) + if err != nil { + return fmt.Errorf("failed to clear past scheduled runs of maintained_apps from cron_stats table: %w", err) + } + return nil }