Currently we install a systemd service named firstboot.service and a
SysV service named virt-sysprep-firstboot. On systems where systemd is
the init system and runs with the SysV compatibility, the different
names make systemd handle them as different services, and thus trying to
run the firstboot script runner twice.
Rename the systemd service to virt-sysprep-firstboot as well: other than
being sligtly less generic, it is also shadowed by the SysV service, and
thus run just once. To avoid leaving the old systemd service behind, a
simple cleanup strategy is in place, checking the content of the old
firstboot.service to really ensure we are removing one of our versions
of this file.
---
customize/firstboot.ml | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/customize/firstboot.ml b/customize/firstboot.ml
index f1e5807..6d7b065 100644
--- a/customize/firstboot.ml
+++ b/customize/firstboot.ml
@@ -122,10 +122,27 @@ WantedBy=default.target
*)
let unitdir = "/usr/lib/systemd/system" in
g#mkdir_p unitdir;
- let unitfile = sprintf "%s/firstboot.service" unitdir in
+ let unitfile = sprintf "%s/virt-sysprep-firstboot.service" unitdir in
g#write unitfile firstboot_service;
g#mkdir_p "/etc/systemd/system/default.target.wants";
- g#ln_sf unitfile "/etc/systemd/system/default.target.wants"
+ g#ln_sf unitfile "/etc/systemd/system/default.target.wants";
+
+ (* Try to remove the old firstboot.service files. *)
+ let oldunitfile = sprintf "%s/firstboot.service" unitdir in
+ if g#is_file oldunitfile then (
+ g#rm_f "/etc/systemd/system/default.target.wants/firstboot.service";
+ (* Remove the old firstboot.service only if it is one of our
+ * versions. *)
+ match g#checksum "md5" oldunitfile with
+ | "6923781f7a1851b40b32b4960eb9a0fc" (* < 1.23.24 *)
+ | "56fafd8c990fc9d24e5b8497f3582e8d" (* < 1.23.32 *)
+ | "a83767e01cf398e2fd7c8f59d65d320a" (* < 1.25.2 *)
+ | "39aeb10df29104797e3a9aca4db37a6e" ->
+ g#rm oldunitfile
+ | csum ->
+ warning (f_"firstboot: unknown version for old firstboot.service file %s
(md5=%s), it will not be removed")
+ oldunitfile csum
+ )
and install_sysvinit_service g = function
|
"fedora"|"rhel"|"centos"|"scientificlinux"|"redhat-based"
->
--
2.7.4