Re: [Libvir] [patch 3/3] Add libvirt_qemud init script
by Daniel P. Berrange
On Fri, Feb 23, 2007 at 12:16:00PM +0000, Mark McLoughlin wrote:
> Add a Red Hat style init script, using the service name
> libvirt_qemud.
I'm wondering about the future where we have Rich's libvirtd to start
up too. Perhaps we should call the init script just 'libvirtd' and
in the future it can either start both libvirt_qemud & libvirtd or
if we merge the two, just start libvirtd. That way we won't have to
worry about possible renaming of the init script during an update.
That question aside, the patches all look fine to me.
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
17 years, 9 months
[Libvir] __attribute__((constructor)) anyone?
by Richard W.M. Jones
Would anyone object to a patch using __attribute__((constructor))
throughout libvirt rather than all this if(!initialised) initialise() stuff?
Rich.
--
Emerging Technologies, Red Hat http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF Mobile: +44 7866 314 421
"[Negative numbers] darken the very whole doctrines of the equations
and make dark of the things which are in their nature excessively
obvious and simple" (Francis Maseres FRS, mathematician, 1759)
17 years, 9 months
[Libvir] [patch 3/3] Add libvirt_qemud init script
by Mark McLoughlin
Add a Red Hat style init script, using the service name
libvirt_qemud.
Also add a --with-init-scripts configure argument to
allow us to add other flavour init scripts.
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: libvirt/qemud/Makefile.am
===================================================================
--- libvirt.orig/qemud/Makefile.am
+++ libvirt/qemud/Makefile.am
@@ -19,3 +19,24 @@ libvirt_qemud_LDFLAGS = $(LIBXML_LIBS) $
libvirt_qemud_DEPENDENCIES =
libvirt_qemud_LDADD =
+EXTRA_DIST = libvirt_qemud.init.in
+
+if LIBVIRT_INIT_SCRIPTS_RED_HAT
+libvirt_qemud.init: libvirt_qemud.init.in
+ sed \
+ -e s!\@localstatedir\@!@localstatedir@! \
+ -e s!\@sbindir\@!@sbindir@! \
+ -e s!\@sysconfdir\@!@sysconfdir@! \
+ < $< > $@
+ chmod a+x libvirt_qemud.init
+
+install-exec-local: libvirt_qemud.init
+ mkdir -p $(DESTDIR)$(sysconfdir)/rc.d/init.d
+ install -m 0755 $(srcdir)/libvirt_qemud.init $(DESTDIR)$(sysconfdir)/rc.d/init.d/libvirt_qemud
+
+uninstall-local:
+ rm -f $(DESTDIR)$(sysconfdir)/rc.d/init.d/libvirt_qemud
+ rmdir $(DESTDIR)$(sysconfdir)/rc.d/init.d || :
+
+CLEANFILES = libvirt_qemud.init
+endif # DBUS_INIT_SCRIPTS_RED_HAT
Index: libvirt/qemud/libvirt_qemud.init.in
===================================================================
--- /dev/null
+++ libvirt/qemud/libvirt_qemud.init.in
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+# libvirt_qemud: QEMU and virtual network management daemon
+#
+# chkconfig: 345 97 03
+# description: This is a daemon for managing QEMU guest instances
+# and libvirt virtual networks
+# See http://libvirt.org
+#
+# processname: libvirt_qemud
+# pidfile: @localstatedir(a)/run/libvirt_qemud.pid
+#
+
+# Sanity checks.
+[ -x @sbindir@/libvirt_qemud ] || exit 0
+
+# Source function library.
+. @sysconfdir(a)/rc.d/init.d/functions
+
+SERVICE=libvirt_qemud
+
+RETVAL=0
+
+start() {
+ echo -n $"Starting $SERVICE daemon: "
+ daemon $SERVICE --system --daemon
+ RETVAL=$?
+ echo
+ [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$SERVICE
+}
+
+stop() {
+ echo -n $"Stopping $SERVICE daemon: "
+
+ killproc $SERVICE -TERM
+ RETVAL=$?
+ echo
+ if [ $RETVAL -eq 0 ]; then
+ rm -f @localstatedir@/lock/subsys/$SERVICE
+ rm -f @localstatedir(a)/run/$SERVICE.pid
+ fi
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ echo -n $"Reloading $SERVICE configuration: "
+
+ killproc $SERVICE -HUP
+ RETVAL=$?
+ echo
+ return $RETVAL
+}
+
+# See how we were called.
+case "$1" in
+ start|stop|restart|reload)
+ $1
+ ;;
+ status)
+ status $SERVICE
+ RETVAL=$?
+ ;;
+ condrestart)
+ [ -f @localstatedir@/lock/subsys/$SERVICE ] && restart || :
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
+ exit 1
+ ;;
+esac
+exit $RETVAL
Index: libvirt/configure.in
===================================================================
--- libvirt.orig/configure.in
+++ libvirt/configure.in
@@ -100,6 +100,23 @@ AC_DEFINE_UNQUOTED(QEMUD_PID_FILE, "$QEM
AC_MSG_RESULT($QEMUD_PID_FILE)
dnl
+dnl init script flavor
+dnl
+AC_MSG_CHECKING([for init script flavor])
+AC_ARG_WITH(init-script,
+ AC_HELP_STRING([--with-init-scripts=[redhat|auto|none]],
+ [Style of init scripts to install (defaults to auto)]))
+if test "x$with_init_scripts" = "x" -o "x$with_init_scripts" = "xauto"; then
+ if test -f /etc/redhat-release ; then
+ with_init_scripts=redhat
+ else
+ with_init_scripts=none
+ fi
+fi
+AM_CONDITIONAL(LIBVIRT_INIT_SCRIPTS_RED_HAT, test x$with_init_scripts = xredhat)
+AC_MSG_RESULT($with_init_scripts)
+
+dnl
dnl allow the creation of iptables rules in chains with a
dnl specific prefix rather than in the standard toplevel chains
dnl
--
17 years, 9 months
[Libvir] [patch 2/3] Add ability to write PID file to qemud
by Mark McLoughlin
Add a --pid-file arg to libvirt_qemud and, in daemon mode,
default to writing a PID file. Passing --pid-file="" disables
writing a PID file.
Also add a --with-qemud-pid-file arg to configure. Passing
--with-pid-file=none disables the default PID file path.
The default path is /var/run/libvirt_qemud.pid in order
to match the service name.
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: libvirt/configure.in
===================================================================
--- libvirt.orig/configure.in
+++ libvirt/configure.in
@@ -87,6 +87,21 @@ if test x"$enable_debug" = x"yes"; then
fi
dnl
+dnl PID file
+dnl
+AC_MSG_CHECKING([where to write libvirt_qemud PID file])
+AC_ARG_WITH(pid-file, AC_HELP_STRING([--with-qemud-pid-file=[pidfile|none]], [PID file for libvirt_qemud]))
+if test "x$with_qemud_pid_file" == "x" ; then
+ QEMUD_PID_FILE="$localstatedir/run/libvirt_qemud.pid"
+elif test "x$with_qemud_pid_file" == "xnone" ; then
+ QEMUD_PID_FILE=""
+else
+ QEMUD_PID_FILE="$with_qemud_pid_file"
+fi
+AC_DEFINE_UNQUOTED(QEMUD_PID_FILE, "$QEMUD_PID_FILE", [PID file path for qemud])
+AC_MSG_RESULT($QEMUD_PID_FILE)
+
+dnl
dnl allow the creation of iptables rules in chains with a
dnl specific prefix rather than in the standard toplevel chains
dnl
Index: libvirt/qemud/qemud.c
===================================================================
--- libvirt.orig/qemud/qemud.c
+++ libvirt/qemud/qemud.c
@@ -301,6 +301,42 @@ static int qemudGoDaemon(void) {
}
}
+static int qemudWritePidFile(const char *pidFile) {
+ int fd;
+ FILE *fh;
+
+ if (pidFile[0] == '\0')
+ return 0;
+
+ if ((fd = open(pidFile, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
+ qemudLog(QEMUD_ERR, "Failed to open pid file '%s' : %s",
+ pidFile, strerror(errno));
+ return -1;
+ }
+
+ if (!(fh = fdopen(fd, "w"))) {
+ qemudLog(QEMUD_ERR, "Failed to fdopen pid file '%s' : %s",
+ pidFile, strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
+ qemudLog(QEMUD_ERR, "Failed to write to pid file '%s' : %s",
+ pidFile, strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ if (fclose(fh) == EOF) {
+ qemudLog(QEMUD_ERR, "Failed to close pid file '%s' : %s",
+ pidFile, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
static int qemudListenUnix(struct qemud_server *server,
const char *path, int readonly) {
struct qemud_socket *sock = calloc(1, sizeof(struct qemud_socket));
@@ -1481,12 +1517,15 @@ int main(int argc, char **argv) {
struct qemud_server *server;
struct sigaction sig_action;
int sigpipe[2];
+ char *pid_file = NULL;
+ int ret = 1;
struct option opts[] = {
{ "verbose", no_argument, &verbose, 1},
{ "daemon", no_argument, &godaemon, 1},
{ "system", no_argument, &sys, 1},
{ "timeout", required_argument, 0, 't'},
+ { "pid-file", required_argument, 0, 'p'},
{0, 0, 0, 0}
};
@@ -1495,7 +1534,7 @@ int main(int argc, char **argv) {
int c;
char *tmp;
- c = getopt_long(argc, argv, "vsdt:", opts, &optidx);
+ c = getopt_long(argc, argv, "vsdt:p:", opts, &optidx);
if (c == -1) {
break;
@@ -1522,6 +1561,11 @@ int main(int argc, char **argv) {
if (timeout <= 0)
timeout = -1;
break;
+
+ case 'p':
+ pid_file = strdup(optarg);
+ break;
+
case '?':
return 2;
break;
@@ -1539,7 +1583,7 @@ int main(int argc, char **argv) {
qemudSetNonBlock(sigpipe[1]) < 0) {
qemudLog(QEMUD_ERR, "Failed to create pipe: %s",
strerror(errno));
- return 1;
+ goto error1;
}
sigwrite = sigpipe[1];
@@ -1562,14 +1606,19 @@ int main(int argc, char **argv) {
if (pid < 0) {
qemudLog(QEMUD_ERR, "Failed to fork as daemon: %s",
strerror(errno));
- return 1;
+ goto error1;
}
if (pid > 0)
- return 0;
+ goto out;
+
+ if (qemudWritePidFile(pid_file ? pid_file : QEMUD_PID_FILE) < 0)
+ goto error1;
}
- if (!(server = qemudInitialize(sys, sigpipe[0])))
- return 2;
+ if (!(server = qemudInitialize(sys, sigpipe[0]))) {
+ ret = 2;
+ goto error2;
+ }
qemudRunLoop(server, timeout);
@@ -1580,7 +1629,18 @@ int main(int argc, char **argv) {
if (godaemon)
closelog();
- return 0;
+ out:
+ ret = 0;
+
+ error2:
+ if (godaemon)
+ unlink(pid_file ? pid_file : QEMUD_PID_FILE);
+
+ error1:
+ if (pid_file)
+ free(pid_file);
+
+ return ret;
}
/*
--
17 years, 9 months
[Libvir] [patch 1/3] Move libvirt_qemud to /usr/sbin
by Mark McLoughlin
Move libvirt_qemud to /usr/sbin since it is now "designed
to be executed by hand" ... i.e. we're adding an initscript
for it rather than just having libvirt start it automatically.
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: libvirt/qemud/Makefile.am
===================================================================
--- libvirt.orig/qemud/Makefile.am
+++ libvirt/qemud/Makefile.am
@@ -2,7 +2,7 @@
INCLUDES = @LIBXML_CFLAGS@
-libexec_PROGRAMS = libvirt_qemud
+sbin_PROGRAMS = libvirt_qemud
libvirt_qemud_SOURCES = qemud.c internal.h protocol.h \
driver.c driver.h \
Index: libvirt/src/Makefile.am
===================================================================
--- libvirt.orig/src/Makefile.am
+++ libvirt/src/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in
INCLUDES = -I$(top_builddir)/include -I@top_srcdir@/include @LIBXML_CFLAGS@ -I@top_srcdir@/qemud \
- -DBINDIR=\""$(libexecdir)"\" -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
+ -DBINDIR=\""$(libexecdir)"\" -DSBINDIR=\""$(sbindir)"\" -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-DLOCAL_STATE_DIR=\""$(localstatedir)"\" \
-DGETTEXT_PACKAGE=\"$(PACKAGE)\"
DEPS = libvirt.la
Index: libvirt/src/qemu_internal.c
===================================================================
--- libvirt.orig/src/qemu_internal.c
+++ libvirt/src/qemu_internal.c
@@ -99,8 +99,8 @@ static const char *
qemuFindServerPath(void)
{
static const char *serverPaths[] = {
- BINDIR "/libvirt_qemud",
- BINDIR "/libvirt_qemud_dbg",
+ SBINDIR "/libvirt_qemud",
+ SBINDIR "/libvirt_qemud_dbg",
NULL
};
int i;
--
17 years, 9 months
[Libvir] PATCH: Autodetect QEMU version
by Daniel P. Berrange
When I tested out the libvirt 0.2.0 in Fedora rawhide I discovered that the
syntax for specifying VNC display numbers changes in QEMU 0.9.0. Previously
you would use
-vnc 7
Now you need to use
-vnc :7
For current Fedora RPM I just hacked in a workaround to always add ':', but
we need to be able to detect the version properly. So I'm attaching a patch
which spawns '/usr/bin/qemu' and groks its command line help to extract the
version number. It then uses appropriate VNC argument syntax based on the
version. At the same time I also check for whether -no-kqemu is available
so we can turn off KQEMU support if it is not available.
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
17 years, 9 months
Re: [Libvir] [patch 3/9] Re-factor chunks of qemuds config handling
by Daniel P. Berrange
On Thu, Feb 22, 2007 at 11:04:37AM +0000, Mark McLoughlin wrote:
> The easiest way to explain where I'm coming from with
> this patch is to look at the current qemudLoadConfigXML().
>
> It's used in three places:
>
> 1) Loading at startup - you want (a) and (b), but you
> want to check whether the name matches the filename
> before doing (b)
>
> 2) Create() - you want (a) and (b)
>
> 3) Define() - you want (a), (b) and (c)
>
> So, mostly I'm just splitting the function into three
> and making the logic above much more obvious. It should
> also make some of the autostart code much more
> straightforward.
Hard to tell from the raw patch exactly how it fits together, but the
principles of the patch all sound good to me - centralizing alot of
the pointer munging into one place & generally tidying stuff up.
BTW, your mailer alias for this list is wrong - its generating a bogus
reply to against
libvirt hacker dudes <libvirt-list(a)redhat.com>
Instead of
libvirt hacker dudes <libvir-list(a)redhat.com>
Note, the extra 't' in the former - which makes replying to your mails a
little error prone - several went to dev null...
Dan
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
17 years, 9 months