T5872: re-write exit hook to always regenerate config
(cherry picked from commit 679b78356cbda4de15f96a7f22d4a98037dbeea4)