[Libguestfs] [PATCH] firstboot: rename systemd service file
Richard W.M. Jones
rjones at redhat.com
Wed Aug 3 15:39:46 UTC 2016
On Wed, Aug 03, 2016 at 05:35:14PM +0200, Pino Toscano wrote:
> 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.
Ok, but can we name it something other than 'sysprep'? eg.
'virt-firstboot.service' or 'guestfs-firstboot.service' or similar?
Rich.
> 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
>
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
More information about the Libguestfs
mailing list