Pino Toscano
2016-Aug-03 15:35 UTC
[Libguestfs] [PATCH] firstboot: rename systemd service file
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
Richard W.M. Jones
2016-Aug-03 15:39 UTC
Re: [Libguestfs] [PATCH] firstboot: rename systemd service file
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@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
Pino Toscano
2016-Aug-03 15:43 UTC
Re: [Libguestfs] [PATCH] firstboot: rename systemd service file
On Wednesday, 3 August 2016 16:39:46 CEST Richard W.M. Jones wrote:> 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?That will involve also renaming the SysV services, and I wanted to limit the amount of changes. However I can do that, if needed. -- Pino Toscano
Maybe Matching Threads
- [PATCH v2 1/2] firstboot: rename systemd and sysvinit
- Re: [PATCH] firstboot: rename systemd service file
- [PATCH v2 0/4] customize: firstboot: Install firstboot scripts in multi-user.target (RHBZ#1469655).
- [PATCH 0/2] customize: firstboot: Install firstboot scripts in multi-user.target (RHBZ#1469655).
- Re: [PATCH] firstboot: rename systemd service file