[libvirt] [PATCH 0/3] libvirt-guests: fix init script to Fedora standards

https://bugzilla.redhat.com/show_bug.cgi?id=617300 documents several shortcoming in our libvirt-guests init script, in relation to Fedora init script standards. For easier review, I've split it into three simpler patches. Eric Blake (3): libvirt-guests: detect invalid arguments libvirt-guests: enhance status libvirt-guests: add reload, condrestart daemon/libvirt-guests.init.in | 46 +++++++++++++++++++++++++++++++++------- 1 files changed, 38 insertions(+), 8 deletions(-) -- 1.7.2

Reject extra arguments. Return the correct status for unknown arguments, as mandated by https://fedoraproject.org/wiki/Packaging/SysVInitScript Add --help, as a permitted extension. * daemon/libvirt-guests.init.in (usage): New function. Use it in more places, and return correct value. --- daemon/libvirt-guests.init.in | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/daemon/libvirt-guests.init.in b/daemon/libvirt-guests.init.in index d2ec96a..3a5b205 100644 --- a/daemon/libvirt-guests.init.in +++ b/daemon/libvirt-guests.init.in @@ -282,8 +282,21 @@ gueststatus() { done } +# usage [val] +# Display usage string, then exit with VAL (defaults to 2). +usage() { + echo $"Usage: $0 {start|stop|restart|force-reload|gueststatus|shutdown}" + exit ${1-2} +} + # See how we were called. +if test $# != 1; then + usage +fi case "$1" in + --help) + usage 0 + ;; start|stop|gueststatus) $1 ;; @@ -304,8 +317,7 @@ case "$1" in stop ;; *) - echo $"Usage: $0 {start|stop|restart|force-reload|gueststatus|shutdown}" - exit 3 + usage ;; esac exit $RETVAL -- 1.7.2

LSB and https://fedoraproject.org/wiki/Packaging/SysVInitScript require status to output something useful, rather than just use the exit code. * daemon/libvirt-guests.init.in (status): Break into new routine, and provide output. (usage): Document status. --- daemon/libvirt-guests.init.in | 26 ++++++++++++++++++++------ 1 files changed, 20 insertions(+), 6 deletions(-) diff --git a/daemon/libvirt-guests.init.in b/daemon/libvirt-guests.init.in index 3a5b205..953b18a 100644 --- a/daemon/libvirt-guests.init.in +++ b/daemon/libvirt-guests.init.in @@ -282,2 +282,2 @@ gueststatus() { done } +# rh_status +# Display current status: whether saved state exists, and whether start +# has been executed. We cannot use status() from the functions library, +# since there is no external daemon process matching this init script. +rh_status() { + if [ -f "$LISTFILE" ]; then + echo $"stopped, with saved guests" + RETVAL=3 + else + if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then + echo $"started" + else + echo $"stopped, with no saved guests" + fi + RETVAL=0 + fi +} + # usage [val] # Display usage string, then exit with VAL (defaults to 2). usage() { - echo $"Usage: $0 {start|stop|restart|force-reload|gueststatus|shutdown}" + echo $"Usage: $0 {start|stop|status|restart|force-reload|gueststatus|shutdown}" exit ${1-2} } @@ -306,11 +324,7 @@ case "$1" in force-reload) ;; status) - if [ -f "$LISTFILE" ]; then - RETVAL=3 - else - RETVAL=0 - fi + rh_status ;; shutdown) ON_SHUTDOWN=shutdown -- 1.7.2

Optional per LSB, but required by Fedora: https://fedoraproject.org/wiki/Packaging/SysVInitScript * daemon/libvirt-guests.init.in (main): Add more required commands. --- daemon/libvirt-guests.init.in | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/daemon/libvirt-guests.init.in b/daemon/libvirt-guests.init.in index 953b18a..960856c 100644 --- a/daemon/libvirt-guests.init.in +++ b/daemon/libvirt-guests.init.in @@ -303,7 +303,7 @@ rh_status() { # usage [val] # Display usage string, then exit with VAL (defaults to 2). usage() { - echo $"Usage: $0 {start|stop|status|restart|force-reload|gueststatus|shutdown}" + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|gueststatus|shutdown}" exit ${1-2} } @@ -321,7 +321,11 @@ case "$1" in restart) stop && start ;; - force-reload) + condrestart|try-restart) + [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ] && stop && start + ;; + reload|force-reload) + # Nothing to do; we reread configuration on each invocation ;; status) rh_status -- 1.7.2

https://bugzilla.redhat.com/show_bug.cgi?id=617300 documents several shortcoming in our libvirt-guests init script, in relation to Fedora init script standards. For easier review, I've split it into three simpler patches.
Eric Blake (3): libvirt-guests: detect invalid arguments libvirt-guests: enhance status libvirt-guests: add reload, condrestart
ACK to all of them. Jirka

On Wed, Jul 28, 2010 at 11:04:34AM +0200, Jiri Denemark wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=617300 documents several shortcoming in our libvirt-guests init script, in relation to Fedora init script standards. For easier review, I've split it into three simpler patches.
Eric Blake (3): libvirt-guests: detect invalid arguments libvirt-guests: enhance status libvirt-guests: add reload, condrestart
ACK to all of them.
Looks fine to me too, ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On 07/28/2010 07:05 AM, Daniel Veillard wrote:
On Wed, Jul 28, 2010 at 11:04:34AM +0200, Jiri Denemark wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=617300 documents several shortcoming in our libvirt-guests init script, in relation to Fedora init script standards. For easier review, I've split it into three simpler patches.
Eric Blake (3): libvirt-guests: detect invalid arguments libvirt-guests: enhance status libvirt-guests: add reload, condrestart
ACK to all of them.
Looks fine to me too, ACK,
Thanks; pushed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (3)
-
Daniel Veillard
-
Eric Blake
-
Jiri Denemark