[libvirt] [PATCH] Add support for systemd init service

2011-11-16 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

This patch adds support for a systemd init service for libvirtd
and libvirt-guests. The libvirtd.service is *not* written to use
socket activation, since we want libvirtd to start on boot so it
can do guest auto-start.

The libvirt-guests.service is pretty lame, just exec'ing the
original init script for now. Ideally we would factor out the
functionality, into some shared tool.

Instead of

  ./configure --with-init-script=redhat

You can now do

  ./configure --with-init-script=systemd

Or better still:

  ./configure --with-init-script=systemd+redhat

We can also now support install of the upstart init script

In v4:

  - Print chosen init script type in configure.ac summary
  - Support upstart install
  - Error from configure on unsupported requests
  - Remove bogus dep from policykit install to redhat init

* configure.ac: Add systemd, and systemd+redhat options to
  --with-init-script option
* daemon/Makefile.am: Install systemd services
* daemon/libvirtd.sysconf: Add note about unused env variable
  with systemd
* daemon/libvirtd.service.in: libvirtd systemd service unit
* libvirt.spec.in: Add scripts to installing systemd services
  and migrating from legacy init scripts
* tools/Makefile.am: Install systemd services
* tools/libvirt-guests.init.sh: Rename to tools/libvirt-guests.init.in
* tools/libvirt-guests.service.in: systemd service unit
---
 configure.ac|   37 +++
 daemon/.gitignore   |1 +
 daemon/Makefile.am  |   98 +-
 daemon/libvirtd.service.in  |   20 
 daemon/libvirtd.sysconf |3 +
 libvirt.spec.in |   93 +++-
 po/POTFILES.in  |2 +-
 tools/Makefile.am   |   61 +++-
 tools/libvirt-guests.service.in |   13 +
 9 files changed, 279 insertions(+), 49 deletions(-)
 create mode 100644 daemon/libvirtd.service.in
 create mode 100644 tools/libvirt-guests.service.in

diff --git a/configure.ac b/configure.ac
index 3b7535e..c663f7b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,16 +329,33 @@ dnl init script flavor
 dnl
 AC_MSG_CHECKING([for init script flavor])
 AC_ARG_WITH([init-script],
-[AC_HELP_STRING([--with-init-script=@:@redhat|auto|none@:@],
-[Style of init script to install @:@default=auto@:@])])
-if test x$with_init_script = x || test x$with_init_script = xauto; then
-if test $cross_compiling = yes || test ! -f /etc/redhat-release; then
-with_init_script=none
-else
-with_init_script=redhat
-fi
-fi
-AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_RED_HAT], test x$with_init_script = 
xredhat)
+[AC_HELP_STRING([--with-init-script@:@=STYLE@:@],
+[Style of init script to install: redhat, systemd, 
systemd+redhat,
+ upstart, auto, none @:@default=auto@:@])])
+init_redhat=no
+init_systemd=no
+case $with_init_script in
+systemd+redhat)
+   init_redhat=yes
+   init_systemd=yes
+   ;;
+systemd)
+   init_systemd=yes
+   ;;
+redhat)
+   init_redhat=yes
+   ;;
+none)
+   ;;
+*)
+   if test $cross_compiling != yes  test -f /etc/redhat-release; then
+  init_redhat=yes
+  with_init_script=redhat
+   fi
+   ;;
+esac
+AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_RED_HAT], test $init_redhat = yes)
+AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_SYSTEMD], test $init_systemd = yes)
 AC_MSG_RESULT($with_init_script)
 
 dnl RHEL-5 has a peculiar version of Xen, which requires some special casing
diff --git a/daemon/.gitignore b/daemon/.gitignore
index ab3d093..2873143 100644
--- a/daemon/.gitignore
+++ b/daemon/.gitignore
@@ -7,6 +7,7 @@ Makefile.in
 libvirt_qemud
 libvirtd
 libvirtd.init
+libvirtd.service
 libvirtd*.logrotate
 libvirtd.8
 libvirtd.8.in
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 59db217..9ccbb5b 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -174,22 +174,25 @@ policyfile = libvirtd.policy-1
 endif
 endif
 
-install-data-local: install-init install-data-sasl install-data-polkit \
-   install-logrotate
+install-data-local: install-init-redhat install-init-systemd 
install-init-upstart \
+   install-data-sasl install-data-polkit \
+   install-logrotate install-sysctl
mkdir -p $(DESTDIR)$(localstatedir)/log/libvirt
mkdir -p $(DESTDIR)$(localstatedir)/run/libvirt
mkdir -p $(DESTDIR)$(localstatedir)/lib/libvirt
 
-uninstall-local:: uninstall-init uninstall-data-sasl uninstall-data-polkit
+uninstall-local:: uninstall-init-redhat uninstall-init-systemd 
uninstall-init-upstart \
+   uninstall-data-sasl uninstall-data-polkit \
+   uninstall-sysctl
rmdir $(DESTDIR)$(localstatedir)/log/libvirt || :
rmdir 

Re: [libvirt] [PATCH] Add support for systemd init service

2011-11-16 Thread Eric Blake
On 11/16/2011 05:01 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 This patch adds support for a systemd init service for libvirtd
 and libvirt-guests. The libvirtd.service is *not* written to use
 socket activation, since we want libvirtd to start on boot so it
 can do guest auto-start.
 
 The libvirt-guests.service is pretty lame, just exec'ing the
 original init script for now. Ideally we would factor out the
 functionality, into some shared tool.
 
 Instead of
 
   ./configure --with-init-script=redhat
 
 You can now do
 
   ./configure --with-init-script=systemd
 
 Or better still:
 
   ./configure --with-init-script=systemd+redhat
 
 We can also now support install of the upstart init script
 
 In v4:
 
   - Print chosen init script type in configure.ac summary
   - Support upstart install
   - Error from configure on unsupported requests
   - Remove bogus dep from policykit install to redhat init
 

 -AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_RED_HAT], test x$with_init_script = 
 xredhat)
 +[AC_HELP_STRING([--with-init-script@:@=STYLE@:@],
 +[Style of init script to install: redhat, 
 systemd, systemd+redhat,
 + upstart, auto, none @:@default=auto@:@])])
 +init_redhat=no
 +init_systemd=no
 +case $with_init_script in
 +systemd+redhat)
 +   init_redhat=yes
 +   init_systemd=yes
 +   ;;
 +systemd)
 +   init_systemd=yes
 +   ;;
 +redhat)
 +   init_redhat=yes
 +   ;;
 +none)
 +   ;;
 +*)
 +   if test $cross_compiling != yes  test -f /etc/redhat-release; then
 +  init_redhat=yes
 +  with_init_script=redhat

Umm, this still has the same problem as v3; with_init_script of upstart
is converted to redhat.  Did you forget to commit your changes?

 +   fi
 +   ;;
 +esac
 +AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_RED_HAT], test $init_redhat = yes)
 +AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_SYSTEMD], test $init_systemd = yes)
  AC_MSG_RESULT($with_init_script)
  

Also, there's a missing AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_UPSTART],...)

 +
 +if LIBVIRT_INIT_SCRIPT_UPSTART

although this expects it to exist.

Everything else looks good, so I'm assuming that the problems in
configure.ac were due to forgetting 'git add' before 'git commit --amend'.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] Add support for systemd init service

2011-11-15 Thread Daniel P. Berrange
On Fri, Nov 11, 2011 at 05:19:33PM +0100, Paolo Bonzini wrote:
 On 11/11/2011 03:32 PM, Daniel P. Berrange wrote:
 +%makeinstall SYSTEMD_UNIT_DIR=%{?buildroot:%{buildroot}}%{_unitdir}
 
 Is this correct since DESTDIR is prepended to it?  Shouldn't it just
 be just %{_unitdir}?  Otherwise looks good; it would be nicer to
 make it a configure option, but that's not too important.

Yes,the %buildroot is not required

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Add support for systemd init service

2011-11-15 Thread Daniel P. Berrange
On Fri, Nov 11, 2011 at 12:18:32PM -0700, Eric Blake wrote:
 On 11/11/2011 07:32 AM, Daniel P. Berrange wrote:
  From: Daniel P. Berrange berra...@redhat.com
  
  This patch adds support for a systemd init service for libvirtd
  and libvirt-guests. The libvirtd.service is *not* written to use
  socket activation, since we want libvirtd to start on boot so it
  can do guest auto-start.
  
 
  +++ b/configure.ac
  @@ -329,16 +329,30 @@ dnl init script flavor
   dnl
   AC_MSG_CHECKING([for init script flavor])
   AC_ARG_WITH([init-script],
  -[AC_HELP_STRING([--with-init-script=@:@redhat|auto|none@:@],
  +
  [AC_HELP_STRING([--with-init-script=@:@redhat|systemd|systemd+redhat|upstart|auto|none@:@],
   [Style of init script to install @:@default=auto@:@])])
 
 That's a bit long.  Perhaps it would be better as:
 
 AC_HELP_STRING([--with-init-script@:@=STYLE@:@],
   [Style of init script to install: redhat, systemd, systemd+redhat,
 upstart, auto, none @:@default=auto@:@])
 
 so that ./configure --help can take advantage of better word wrap

Yep, done that.

  -AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_RED_HAT], test x$with_init_script = 
  xredhat)
  +init_redhat=no
  +init_systemd=no
  +case $with_init_script in
  +systemd+redhat)
  +   init_redhat=yes
  +   init_systemd=yes
  +   ;;
  +systemd)
  +   init_systemd=yes
  +   ;;
  +redhat)
  +   init_redhat=yes
  +   ;;
  +*)
  +   if test $cross_compiling != yes  test -f /etc/redhat-release; 
  then
  +  init_redhat=yes
  +  with_init_script=redhat
 
 Shouldn't this line be 'init_redhat=yes'?

No, we already set that on the line above. This line is setting the
CLI arg variable, so a later AC_MSG_RESULT shows 'redhat'.

  @@ -111,6 +112,11 @@
   %define with_hyperv 0
   %endif
   
  +# Although earlier Fedora has systemd, libvirt still used sysvinit
  +%if 0%{?fedora} = 17
  +%define with_systemd 1
  +%endif
 
 But if we use the configure option, then what's to stop the systemd
 script from working in older Fedora?  That is, why not make this = 16,
 not 17, so that people using the virt-preview repo to get 0.9.8 on F16
 will benefit from systemd?

I didn't want todo that, because switching between init systems is a bit
complex, and if someone installs this and then tries to downgrade to the
original distro packages the results will not be pleasant.

 
  +++ b/po/POTFILES.in
  @@ -151,5 +151,5 @@ src/xenapi/xenapi_utils.c
   src/xenxs/xen_sxpr.c
   src/xenxs/xen_xm.c
   tools/console.c
  -tools/libvirt-guests.init.sh
  +tools/libvirt-guests.init.in
 ...
  diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.in
  similarity index 100%
  rename from tools/libvirt-guests.init.sh
  rename to tools/libvirt-guests.init.in
 
 I'm a bit worried on whether this will do the correct things with
 translations embedded in the file.  My recollection was that we _had_ to
 name it .sh instead of .in in order to get xgettext to properly parse
 out the strings marked for translations into the .pot file.  I haven't
 yet double-checked the resulting .pot file pre- and post-patch, but
 think you may have to revert this particular change.

Ok, I reverted this rename

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Add support for systemd init service

2011-11-11 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

This patch adds support for a systemd init service for libvirtd
and libvirt-guests. The libvirtd.service is *not* written to use
socket activation, since we want libvirtd to start on boot so it
can do guest auto-start.

The libvirt-guests.service is pretty lame, just exec'ing the
original init script for now. Ideally we would factor out the
functionality, into some shared tool.

Instead of

  ./configure --with-init-script=redhat

You can now do

  ./configure --with-init-script=systemd

Or better still:

  ./configure --with-init-script=systemd+redhat

* configure.ac: Add systemd, and systemd+redhat options to
  --with-init-script option
* daemon/Makefile.am: Install systemd services
* daemon/libvirtd.sysconf: Add note about unused env variable
  with systemd
* daemon/libvirtd.service.in: libvirtd systemd service unit
* libvirt.spec.in: Add scripts to installing systemd services
  and migrating from legacy init scripts
* tools/Makefile.am: Install systemd services
* tools/libvirt-guests.init.sh: Rename to tools/libvirt-guests.init.in
* tools/libvirt-guests.service.in: systemd service unit
---
 configure.ac   |   32 +--
 daemon/.gitignore  |1 +
 daemon/Makefile.am |   77 -
 daemon/libvirtd.service.in |   20 
 daemon/libvirtd.sysconf|3 +
 libvirt.spec.in|   93 +++-
 po/POTFILES.in |2 +-
 tools/Makefile.am  |   63 +++---
 ...bvirt-guests.init.sh = libvirt-guests.init.in} |0
 tools/libvirt-guests.service.in|   13 +++
 10 files changed, 257 insertions(+), 47 deletions(-)
 create mode 100644 daemon/libvirtd.service.in
 rename tools/{libvirt-guests.init.sh = libvirt-guests.init.in} (100%)
 create mode 100644 tools/libvirt-guests.service.in

diff --git a/configure.ac b/configure.ac
index 3b7535e..f155666 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,16 +329,30 @@ dnl init script flavor
 dnl
 AC_MSG_CHECKING([for init script flavor])
 AC_ARG_WITH([init-script],
-[AC_HELP_STRING([--with-init-script=@:@redhat|auto|none@:@],
+
[AC_HELP_STRING([--with-init-script=@:@redhat|systemd|systemd+redhat|upstart|auto|none@:@],
 [Style of init script to install @:@default=auto@:@])])
-if test x$with_init_script = x || test x$with_init_script = xauto; then
-if test $cross_compiling = yes || test ! -f /etc/redhat-release; then
-with_init_script=none
-else
-with_init_script=redhat
-fi
-fi
-AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_RED_HAT], test x$with_init_script = 
xredhat)
+init_redhat=no
+init_systemd=no
+case $with_init_script in
+systemd+redhat)
+   init_redhat=yes
+   init_systemd=yes
+   ;;
+systemd)
+   init_systemd=yes
+   ;;
+redhat)
+   init_redhat=yes
+   ;;
+*)
+   if test $cross_compiling != yes  test -f /etc/redhat-release; then
+  init_redhat=yes
+  with_init_script=redhat
+   fi
+   ;;
+esac
+AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_RED_HAT], test $init_redhat = yes)
+AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_SYSTEMD], test $init_systemd = yes)
 AC_MSG_RESULT($with_init_script)
 
 dnl RHEL-5 has a peculiar version of Xen, which requires some special casing
diff --git a/daemon/.gitignore b/daemon/.gitignore
index ab3d093..2873143 100644
--- a/daemon/.gitignore
+++ b/daemon/.gitignore
@@ -7,6 +7,7 @@ Makefile.in
 libvirt_qemud
 libvirtd
 libvirtd.init
+libvirtd.service
 libvirtd*.logrotate
 libvirtd.8
 libvirtd.8.in
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index e8c47ae..92b6b86 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -170,13 +170,14 @@ policyfile = libvirtd.policy-1
 endif
 endif
 
-install-data-local: install-init install-data-sasl install-data-polkit \
-   install-logrotate
+install-data-local: install-init install-systemd install-data-sasl 
install-data-polkit \
+   install-logrotate install-sysctl
mkdir -p $(DESTDIR)$(localstatedir)/log/libvirt
mkdir -p $(DESTDIR)$(localstatedir)/run/libvirt
mkdir -p $(DESTDIR)$(localstatedir)/lib/libvirt
 
-uninstall-local:: uninstall-init uninstall-data-sasl uninstall-data-polkit
+uninstall-local:: uninstall-init uninstall-systemd uninstall-data-sasl 
uninstall-data-polkit \
+ uninstall-sysctl
rmdir $(DESTDIR)$(localstatedir)/log/libvirt || :
rmdir $(DESTDIR)$(localstatedir)/run/libvirt || :
rmdir $(DESTDIR)$(localstatedir)/lib/libvirt || :
@@ -234,25 +235,56 @@ install-logrotate: $(LOGROTATE_CONFS)
$(INSTALL_DATA) libvirtd.lxc.logrotate 
$(DESTDIR)$(sysconfdir)/logrotate.d/libvirtd.lxc
$(INSTALL_DATA) 

Re: [libvirt] [PATCH] Add support for systemd init service

2011-11-11 Thread Paolo Bonzini

On 11/11/2011 03:32 PM, Daniel P. Berrange wrote:

+%makeinstall SYSTEMD_UNIT_DIR=%{?buildroot:%{buildroot}}%{_unitdir}


Is this correct since DESTDIR is prepended to it?  Shouldn't it just be 
just %{_unitdir}?  Otherwise looks good; it would be nicer to make it a 
configure option, but that's not too important.


Paolo

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Add support for systemd init service

2011-11-11 Thread Eric Blake
On 11/11/2011 07:32 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 This patch adds support for a systemd init service for libvirtd
 and libvirt-guests. The libvirtd.service is *not* written to use
 socket activation, since we want libvirtd to start on boot so it
 can do guest auto-start.
 

 +++ b/configure.ac
 @@ -329,16 +329,30 @@ dnl init script flavor
  dnl
  AC_MSG_CHECKING([for init script flavor])
  AC_ARG_WITH([init-script],
 -[AC_HELP_STRING([--with-init-script=@:@redhat|auto|none@:@],
 +
 [AC_HELP_STRING([--with-init-script=@:@redhat|systemd|systemd+redhat|upstart|auto|none@:@],
[Style of init script to install @:@default=auto@:@])])

That's a bit long.  Perhaps it would be better as:

AC_HELP_STRING([--with-init-script@:@=STYLE@:@],
  [Style of init script to install: redhat, systemd, systemd+redhat,
upstart, auto, none @:@default=auto@:@])

so that ./configure --help can take advantage of better word wrap

 -AM_CONDITIONAL([LIBVIRT_INIT_SCRIPT_RED_HAT], test x$with_init_script = 
 xredhat)
 +init_redhat=no
 +init_systemd=no
 +case $with_init_script in
 +systemd+redhat)
 +   init_redhat=yes
 +   init_systemd=yes
 +   ;;
 +systemd)
 +   init_systemd=yes
 +   ;;
 +redhat)
 +   init_redhat=yes
 +   ;;
 +*)
 +   if test $cross_compiling != yes  test -f /etc/redhat-release; then
 +  init_redhat=yes
 +  with_init_script=redhat

Shouldn't this line be 'init_redhat=yes'?

 @@ -111,6 +112,11 @@
  %define with_hyperv 0
  %endif
  
 +# Although earlier Fedora has systemd, libvirt still used sysvinit
 +%if 0%{?fedora} = 17
 +%define with_systemd 1
 +%endif

But if we use the configure option, then what's to stop the systemd
script from working in older Fedora?  That is, why not make this = 16,
not 17, so that people using the virt-preview repo to get 0.9.8 on F16
will benefit from systemd?

 +++ b/po/POTFILES.in
 @@ -151,5 +151,5 @@ src/xenapi/xenapi_utils.c
  src/xenxs/xen_sxpr.c
  src/xenxs/xen_xm.c
  tools/console.c
 -tools/libvirt-guests.init.sh
 +tools/libvirt-guests.init.in
...
 diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.in
 similarity index 100%
 rename from tools/libvirt-guests.init.sh
 rename to tools/libvirt-guests.init.in

I'm a bit worried on whether this will do the correct things with
translations embedded in the file.  My recollection was that we _had_ to
name it .sh instead of .in in order to get xgettext to properly parse
out the strings marked for translations into the .pot file.  I haven't
yet double-checked the resulting .pot file pre- and post-patch, but
think you may have to revert this particular change.

Overall, though, I think the patch is good.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list