The current libvirt-guest init script only prints to stdout, which isn't shown when using a graphical splash screen: During a reboot the shutdown screen might not show any progress while the domains are suspended. This patch mostly drops the use of gettext and gettext_eval and used the appropriate lsb_*-functions. Splash screens integrate with LSB compatibe init scripts by overwriting the lsb_*-functions defined in /lib/lsb/init-functions. Signed-off-by: Philipp Hahn <hahn@xxxxxxxxxxxxx> --- tools/libvirt-guests.init.sh | 67 +++++++++++++++++++++-------------------- 1 files changed, 34 insertions(+), 33 deletions(-) diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.sh index 8da7576..00030b8 100644 --- a/tools/libvirt-guests.init.sh +++ b/tools/libvirt-guests.init.sh @@ -36,6 +36,8 @@ test ! -r "$sysconfdir"/rc.d/init.d/functions || # Make sure this file is recognized as having translations: _("dummy") . "@bindir@"/gettext.sh +. /lib/lsb/init-functions + export TEXTDOMAIN="@PACKAGE@" TEXTDOMAINDIR="@localedir@" URIS=default @@ -139,8 +141,7 @@ start() { [ -f "$LISTFILE" ] || { started; return 0; } if [ "x$ON_BOOT" != xstart ]; then - gettext "libvirt-guests is configured not to start any guests on boot" - echo + log_action_msg "libvirt-guests is configured not to start any guests on boot" rm -f "$LISTFILE" started return 0 @@ -155,20 +156,20 @@ start() { fi done if ! "$configured"; then - eval_gettext "Ignoring guests on \$uri URI"; echo + log_action_msg "Ignoring guests on $uri URI" continue fi - eval_gettext "Resuming guests on \$uri URI..."; echo + log_action_msg "Resuming guests on $uri URI..." for guest in $list; do name=$(guest_name "$uri" "$guest") - eval_gettext "Resuming guest \$name: " + log_action_begin_msg "Resuming guest $name: " if guest_is_on "$uri" "$guest"; then if "$guest_running"; then - gettext "already active"; echo + log_action_end_msg 0 "already active" else retval run_virsh "$uri" start "$name" >/dev/null && \ - gettext "done"; echo + log_action_end_msg 0 "done" fi fi done @@ -185,22 +186,26 @@ suspend_guest() guest=$2 name=$(guest_name "$uri" "$guest") - label=$(eval_gettext "Suspending \$name: ") - printf %s "$label" + log_action_begin_msg "Suspending $name: " run_virsh "$uri" managedsave "$guest" >/dev/null & virsh_pid=$! while true; do sleep 1 kill -0 "$virsh_pid" >/dev/null 2>&1 || break progress=$(run_virsh_c "$uri" domjobinfo "$guest" 2>/dev/null | \ - awk '/^Data processed:/{print $3, $4}') + awk ' + BEGIN {processed=0;total=0} + /^Data processed:/ {processed=$3} + /^Data total:/ {total=$3} + END {if(processed>=0 && total>0) printf "%d\n", processed/total * 100} + ') if [ -n "$progress" ]; then - printf '\r%s%12s ' "$label" "$progress" + log_action_cont_msg "${progress}%" else - printf '\r%s%-12s ' "$label" "..." + log_action_cont_msg "..." fi done - retval wait "$virsh_pid" && printf '\r%s%-12s\n' "$label" "$(gettext "done")" + retval wait "$virsh_pid" && log_action_end_msg 0 "done" } shutdown_guest() @@ -210,8 +215,7 @@ shutdown_guest() guest=$2 name=$(guest_name "$uri" "$guest") - label=$(eval_gettext "Shutting down \$name: ") - printf %s "$label" + log_action_begin_msg "Shutting down $name: " retval run_virsh "$uri" shutdown "$guest" >/dev/null || return timeout=$SHUTDOWN_TIMEOUT while [ "$timeout" -gt 0 ]; do @@ -219,15 +223,14 @@ shutdown_guest() timeout=$((timeout - 1)) guest_is_on "$uri" "$guest" || return "$guest_running" || break - printf '\r%s%-12d ' "$label" "$timeout" + log_action_cont_msg "$timeout" done if guest_is_on "$uri" "$guest"; then if "$guest_running"; then - printf '\r%s%-12s\n' "$label" \ - "$(gettext "failed to shutdown in time")" + log_action_end_msg 1 "failed to shutdown in time" else - printf '\r%s%-12s\n' "$label" "$(gettext "done")" + log_action_end_msg 0 "done" fi fi } @@ -241,8 +244,7 @@ stop() { if [ "x$ON_SHUTDOWN" = xshutdown ]; then suspending=false if [ $SHUTDOWN_TIMEOUT -le 0 ]; then - gettext "Shutdown action requested but SHUTDOWN_TIMEOUT was not set" - echo + log_failure_msg "Shutdown action requested but SHUTDOWN_TIMEOUT was not set" RETVAL=6 return fi @@ -250,25 +252,24 @@ stop() { : >"$LISTFILE" for uri in $URIS; do - eval_gettext "Running guests on \$uri URI: " - if [ "x$uri" = xdefault ] && [ ! -x "$libvirtd" ]; then - gettext "libvirtd not installed; skipping this URI."; echo + log_failure_msg "libvirtd not installed; skipping URI $uri." continue fi + log_action_begin_msg "Running guests on $uri URI: " + list=$(list_guests "$uri") if [ $? -eq 0 ]; then empty=true for uuid in $list; do - "$empty" || printf ", " - printf %s "$(guest_name "$uri" "$uuid")" + log_action_cont_msg "$(guest_name "$uri" "$uuid")" empty=false done if "$empty"; then - gettext "no running guests."; echo + log_action_end_msg 0 "no running guests." else - echo + log_action_end_msg 0 echo "$uri" "$list" >>"$LISTFILE" fi fi @@ -276,9 +277,9 @@ stop() { while read uri list; do if "$suspending"; then - eval_gettext "Suspending guests on \$uri URI..."; echo + log_action_msg "Suspending guests on $uri URI..." else - eval_gettext "Shutting down guests on \$uri URI..."; echo + log_action_msg "Shutting down guests on $uri URI..." fi for guest in $list; do @@ -307,13 +308,13 @@ gueststatus() { # since there is no external daemon process matching this init script. rh_status() { if [ -f "$LISTFILE" ]; then - gettext "stopped, with saved guests"; echo + log_action_msg "stopped, with saved guests" RETVAL=3 else if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then - gettext "started"; echo + log_action_msg "started" else - gettext "stopped, with no saved guests"; echo + log_action_msg "stopped, with no saved guests" fi RETVAL=0 fi -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list