2010-05-14 17:37:55 +04:00
#!/bin/sh
2014-07-25 13:46:10 +04:00
# Copyright (C) 2011-2014 Red Hat, Inc.
2013-05-15 03:42:12 +04:00
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
2011-01-04 21:13:56 +03:00
sysconfdir = "@sysconfdir@"
localstatedir = "@localstatedir@"
libvirtd = "@sbindir@" /libvirtd
2010-05-14 17:37:55 +04:00
# Source function library.
2010-12-18 03:26:03 +03:00
test ! -r " $sysconfdir " /rc.d/init.d/functions ||
2011-01-04 21:13:56 +03:00
. " $sysconfdir " /rc.d/init.d/functions
# Source gettext library.
# Make sure this file is recognized as having translations: _("dummy")
. "@bindir@" /gettext.sh
export TEXTDOMAIN = "@PACKAGE@" TEXTDOMAINDIR = "@localedir@"
2010-05-14 17:37:55 +04:00
URIS = default
ON_BOOT = start
ON_SHUTDOWN = suspend
2012-02-28 19:09:42 +04:00
SHUTDOWN_TIMEOUT = 300
PARALLEL_SHUTDOWN = 0
2011-04-15 12:57:06 +04:00
START_DELAY = 0
2011-07-15 03:22:53 +04:00
BYPASS_CACHE = 0
2015-05-11 19:18:39 +03:00
SYNC_TIME = 0
2010-05-14 17:37:55 +04:00
2011-01-04 21:13:56 +03:00
test -f " $sysconfdir " /sysconfig/libvirt-guests &&
. " $sysconfdir " /sysconfig/libvirt-guests
2010-05-14 17:37:55 +04:00
LISTFILE = " $localstatedir " /lib/libvirt/libvirt-guests
2010-05-27 16:47:11 +04:00
VAR_SUBSYS_LIBVIRT_GUESTS = " $localstatedir " /lock/subsys/libvirt-guests
2010-05-14 17:37:55 +04:00
RETVAL = 0
2012-02-28 16:58:59 +04:00
# retval COMMAND ARGUMENTS...
# run command with arguments and convert non-zero return value to 1 and set
# the global return variable
2010-05-14 17:37:55 +04:00
retval( ) {
" $@ "
if [ $? -ne 0 ] ; then
RETVAL = 1
return 1
else
return 0
fi
}
2012-02-28 16:58:59 +04:00
# run_virsh URI ARGUMENTS...
# start virsh and let it execute ARGUMENTS on URI
# If URI is "default" virsh is called without the "-c" argument
# (using libvirt's default connection)
2010-05-14 17:37:55 +04:00
run_virsh( ) {
2020-03-29 13:44:43 +03:00
local uri = $1
2010-05-14 17:37:55 +04:00
shift
if [ " x $uri " = xdefault ] ; then
2011-03-09 11:54:57 +03:00
virsh " $@ " </dev/null
2010-05-14 17:37:55 +04:00
else
2011-03-09 11:54:57 +03:00
virsh -c " $uri " " $@ " </dev/null
2010-05-14 17:37:55 +04:00
fi
}
2012-02-28 16:58:59 +04:00
# run_virsh_c URI ARGUMENTS
# Same as "run_virsh" but the "C" locale is used instead of
# the system's locale.
2010-05-14 17:37:55 +04:00
run_virsh_c( ) {
( export LC_ALL = C; run_virsh " $@ " )
}
2012-02-28 17:39:17 +04:00
# test_connect URI
# check if URI is reachable
test_connect( )
{
2020-03-29 13:44:43 +03:00
local uri = $1
2012-02-28 17:39:17 +04:00
2019-12-16 10:20:59 +03:00
if run_virsh " $uri " connect 2>/dev/null; then
return 0;
else
eval_gettext "Can't connect to \$uri. Skipping."
return 1
fi
2012-02-28 17:39:17 +04:00
}
2012-02-28 16:58:59 +04:00
# list_guests URI PERSISTENT
# List running guests on URI.
# PERSISTENT argument options:
# --persistent: list only persistent guests
# --transient: list only transient guests
# [none]: list both persistent and transient guests
2010-05-14 17:37:55 +04:00
list_guests( ) {
2020-03-29 13:44:43 +03:00
local uri = $1
local persistent = $2
local list = $( run_virsh_c " $uri " list --uuid $persistent )
2010-05-14 17:37:55 +04:00
if [ $? -ne 0 ] ; then
RETVAL = 1
return 1
fi
2017-12-16 01:28:49 +03:00
echo " $list " | sed "/00000000-0000-0000-0000-000000000000/d"
2010-05-14 17:37:55 +04:00
}
2012-02-28 16:58:59 +04:00
# guest_name URI UUID
# return name of guest UUID on URI
2010-05-14 17:37:55 +04:00
guest_name( ) {
2020-03-29 13:44:43 +03:00
local uri = $1
local uuid = $2
2010-05-14 17:37:55 +04:00
2012-02-28 16:58:59 +04:00
run_virsh " $uri " domname " $uuid " 2>/dev/null
2010-05-14 17:37:55 +04:00
}
2012-02-28 16:58:59 +04:00
# guest_is_on URI UUID
# check if guest UUID on URI is running
# Result is returned by variable "guest_running"
2010-05-14 17:37:55 +04:00
guest_is_on( ) {
2020-03-29 13:44:43 +03:00
local uri = $1
local uuid = $2
local id = $( run_virsh " $uri " domid " $uuid " )
2010-05-14 17:37:55 +04:00
guest_running = false
if [ $? -ne 0 ] ; then
RETVAL = 1
return 1
fi
[ -n " $id " ] && [ " x $id " != x- ] && guest_running = true
return 0
}
2012-02-28 16:58:59 +04:00
# started
# Create the startup lock file
2010-05-27 16:47:11 +04:00
started( ) {
touch " $VAR_SUBSYS_LIBVIRT_GUESTS "
}
2012-02-28 16:58:59 +04:00
# start
# Start or resume the guests
2010-05-14 17:37:55 +04:00
start( ) {
2020-03-29 13:44:43 +03:00
local isfirst = true
local bypass =
local sync_time = false
local uri =
local list =
2010-05-27 16:47:11 +04:00
[ -f " $LISTFILE " ] || { started; return 0; }
2010-05-14 17:37:55 +04:00
if [ " x $ON_BOOT " != xstart ] ; then
2011-01-04 21:13:56 +03:00
gettext "libvirt-guests is configured not to start any guests on boot"
echo
2010-05-27 16:47:11 +04:00
rm -f " $LISTFILE "
started
2010-05-14 17:37:55 +04:00
return 0
fi
2011-07-15 03:22:53 +04:00
test " x $BYPASS_CACHE " = x0 || bypass = --bypass-cache
2015-02-18 13:59:22 +03:00
test " x $SYNC_TIME " = x0 || sync_time = true
2010-05-14 17:37:55 +04:00
while read uri list; do
2020-03-29 13:44:43 +03:00
local configured = false
local confuri =
local guest =
2011-03-12 00:06:09 +03:00
set -f
2010-05-14 17:37:55 +04:00
for confuri in $URIS ; do
2011-03-12 00:06:09 +03:00
set +f
2011-03-09 11:54:57 +03:00
if [ " x $confuri " = " x $uri " ] ; then
2010-05-14 17:37:55 +04:00
configured = true
break
fi
done
2011-03-12 00:06:09 +03:00
set +f
2011-03-09 11:54:57 +03:00
if ! " $configured " ; then
2011-01-04 21:13:56 +03:00
eval_gettext "Ignoring guests on \$uri URI" ; echo
2010-05-14 17:37:55 +04:00
continue
fi
2012-02-28 17:39:17 +04:00
test_connect " $uri " || continue
2011-01-04 21:13:56 +03:00
eval_gettext "Resuming guests on \$uri URI..." ; echo
2010-05-14 17:37:55 +04:00
for guest in $list ; do
2020-03-29 13:44:43 +03:00
local name = $( guest_name " $uri " " $guest " )
2011-01-04 21:13:56 +03:00
eval_gettext "Resuming guest \$name: "
2011-03-09 11:54:57 +03:00
if guest_is_on " $uri " " $guest " ; then
if " $guest_running " ; then
2011-01-04 21:13:56 +03:00
gettext "already active" ; echo
2010-05-14 17:37:55 +04:00
else
2011-04-15 12:57:06 +04:00
if " $isfirst " ; then
isfirst = false
else
sleep $START_DELAY
fi
2011-07-15 03:22:53 +04:00
retval run_virsh " $uri " start $bypass " $name " \
>/dev/null && \
2011-01-04 21:13:56 +03:00
gettext "done" ; echo
2015-02-18 13:59:22 +03:00
if " $sync_time " ; then
run_virsh " $uri " domtime --sync " $name " >/dev/null
fi
2010-05-14 17:37:55 +04:00
fi
fi
done
2010-05-27 16:47:11 +04:00
done <" $LISTFILE "
2010-05-14 17:37:55 +04:00
2010-05-27 16:47:11 +04:00
rm -f " $LISTFILE "
started
2010-05-14 17:37:55 +04:00
}
2012-02-28 16:58:59 +04:00
# suspend_guest URI GUEST
# Do a managed save on a GUEST on URI. This function returns after the guest
# was saved.
2010-05-14 17:37:55 +04:00
suspend_guest( )
{
2020-03-29 13:44:43 +03:00
local uri = $1
local guest = $2
local name = $( guest_name " $uri " " $guest " )
local label = $( eval_gettext "Suspending \$name: " )
local bypass =
local slept = 0
2010-05-14 17:37:55 +04:00
2011-07-15 03:22:53 +04:00
test " x $BYPASS_CACHE " = x0 || bypass = --bypass-cache
2012-08-21 19:03:40 +04:00
printf '%s...\n' " $label "
2011-07-15 03:22:53 +04:00
run_virsh " $uri " managedsave $bypass " $guest " >/dev/null &
2020-03-29 13:44:43 +03:00
local virsh_pid = $!
2010-05-14 17:37:55 +04:00
while true; do
sleep 1
2011-03-09 11:54:57 +03:00
kill -0 " $virsh_pid " >/dev/null 2>& 1 || break
2012-08-21 19:03:40 +04:00
slept = $(( $slept + 1 ))
if [ $(( $slept % 5 )) -eq 0 ] ; then
2020-03-29 13:44:43 +03:00
local progress = $( run_virsh_c " $uri " domjobinfo " $guest " 2>/dev/null | \
2012-08-21 19:03:40 +04:00
awk '/^Data processed:/{print $3, $4}' )
if [ -n " $progress " ] ; then
printf '%s%s\n' " $label " " $progress "
else
printf '%s%s\n' " $label " "..."
fi
2010-05-14 17:37:55 +04:00
fi
done
2012-08-21 19:03:40 +04:00
retval wait " $virsh_pid " && printf '%s%s\n' " $label " " $( gettext "done" ) "
2010-05-14 17:37:55 +04:00
}
2012-02-28 16:58:59 +04:00
# shutdown_guest URI GUEST
2014-07-25 13:46:10 +04:00
# Start an ACPI shutdown of GUEST on URI. This function returns after the guest
# was successfully shutdown or the timeout defined by $SHUTDOWN_TIMEOUT expired.
2010-05-14 17:37:55 +04:00
shutdown_guest( )
{
2020-03-29 13:44:43 +03:00
local uri = $1
local guest = $2
local name = $( guest_name " $uri " " $guest " )
local timeout = $SHUTDOWN_TIMEOUT
local check_timeout = false
local format =
local slept =
2010-05-14 17:37:55 +04:00
2012-08-21 19:03:40 +04:00
eval_gettext "Starting shutdown on guest: \$name"
echo
2011-03-09 11:54:57 +03:00
retval run_virsh " $uri " shutdown " $guest " >/dev/null || return
2020-03-29 13:44:43 +03:00
2012-02-28 19:09:42 +04:00
if [ $timeout -gt 0 ] ; then
check_timeout = true
2012-08-21 19:03:40 +04:00
format = $( eval_gettext "Waiting for guest %s to shut down, %d seconds left\n" )
else
slept = 0
format = $( eval_gettext "Waiting for guest %s to shut down\n" )
2012-02-28 19:09:42 +04:00
fi
while ! $check_timeout || [ " $timeout " -gt 0 ] ; do
2010-05-14 17:37:55 +04:00
sleep 1
2011-03-09 11:54:57 +03:00
guest_is_on " $uri " " $guest " || return
" $guest_running " || break
2012-08-21 19:03:40 +04:00
2012-02-28 19:09:42 +04:00
if $check_timeout ; then
2012-08-21 19:03:40 +04:00
if [ $(( $timeout % 5 )) -eq 0 ] ; then
printf " $format " " $name " " $timeout "
fi
timeout = $(( $timeout - 1 ))
else
slept = $(( $slept + 1 ))
if [ $(( $slept % 5 )) -eq 0 ] ; then
printf " $format " " $name "
fi
2012-02-28 19:09:42 +04:00
fi
2010-05-14 17:37:55 +04:00
done
2011-03-09 11:54:57 +03:00
if guest_is_on " $uri " " $guest " ; then
if " $guest_running " ; then
2012-08-21 19:03:40 +04:00
eval_gettext "Shutdown of guest \$name failed to complete in time."
2010-05-14 17:37:55 +04:00
else
2012-08-21 19:03:40 +04:00
eval_gettext "Shutdown of guest \$name complete."
2010-05-14 17:37:55 +04:00
fi
2013-03-20 18:54:08 +04:00
echo
2010-05-14 17:37:55 +04:00
fi
}
2012-02-28 19:09:42 +04:00
# shutdown_guest_async URI GUEST
# Start a ACPI shutdown of GUEST on URI. This function returns after the command
# was issued to libvirt to allow parallel shutdown.
shutdown_guest_async( )
{
2020-03-29 13:44:43 +03:00
local uri = $1
local guest = $2
local name = $( guest_name " $uri " " $guest " )
2012-02-28 19:09:42 +04:00
eval_gettext "Starting shutdown on guest: \$name"
echo
retval run_virsh " $uri " shutdown " $guest " > /dev/null
}
# guest_count GUEST_LIST
# Returns number of guests in GUEST_LIST
guest_count( )
{
set -- $1
echo $#
}
# check_guests_shutdown URI GUESTS
# check if shutdown is complete on guests in "GUESTS" and returns only
# guests that are still shutting down
2018-01-16 18:05:26 +03:00
# Result is returned in "guests_shutting_down"
2012-02-28 19:09:42 +04:00
check_guests_shutdown( )
{
2020-03-29 13:44:43 +03:00
local uri = $1
local guests_to_check = $2
local guest =
2012-02-28 19:09:42 +04:00
2018-01-16 18:05:26 +03:00
guests_shutting_down =
2018-04-19 09:41:02 +03:00
for guest in $guests_to_check ; do
if ! guest_is_on " $uri " " $guest " >/dev/null 2>& 1; then
2012-02-28 19:09:42 +04:00
eval_gettext "Failed to determine state of guest: \$guest. Not tracking it anymore."
echo
continue
fi
if " $guest_running " ; then
2018-01-16 18:05:26 +03:00
guests_shutting_down = " $guests_shutting_down $guest "
2012-02-28 19:09:42 +04:00
fi
done
}
# print_guests_shutdown URI BEFORE AFTER
# Checks for differences in the lists BEFORE and AFTER and prints
# a shutdown complete notice for guests that have finished
print_guests_shutdown( )
{
2020-03-29 13:44:43 +03:00
local uri = $1
local before = $2
local after = $3
local guest =
2012-02-28 19:09:42 +04:00
for guest in $before ; do
case " $after " in
*" $guest " *) continue ; ;
esac
2020-03-29 13:44:43 +03:00
local name = $( guest_name " $uri " " $guest " )
2018-04-19 09:41:03 +03:00
if [ -n " $name " ] ; then
eval_gettext "Shutdown of guest \$name complete."
echo
fi
2012-02-28 19:09:42 +04:00
done
}
# shutdown_guests_parallel URI GUESTS
# Shutdown guests GUESTS on machine URI in parallel
shutdown_guests_parallel( )
{
2020-03-29 13:44:43 +03:00
local uri = $1
local guests = $2
local on_shutdown =
local check_timeout = false
local timeout = $SHUTDOWN_TIMEOUT
local slept =
local format =
2012-02-28 19:09:42 +04:00
if [ $timeout -gt 0 ] ; then
check_timeout = true
2012-08-21 19:03:40 +04:00
format = $( eval_gettext "Waiting for %d guests to shut down, %d seconds left\n" )
else
slept = 0
format = $( eval_gettext "Waiting for %d guests to shut down\n" )
2012-02-28 19:09:42 +04:00
fi
while [ -n " $on_shutdown " ] || [ -n " $guests " ] ; do
while [ -n " $guests " ] &&
[ $( guest_count " $on_shutdown " ) -lt " $PARALLEL_SHUTDOWN " ] ; do
set -- $guests
2020-03-29 13:44:43 +03:00
local guest = $1
2012-02-28 19:09:42 +04:00
shift
guests = $*
2018-01-16 18:05:26 +03:00
if [ -z " $( echo $on_shutdown | grep $guest ) " ] &&
[ -n " $( guest_name " $uri " " $guest " ) " ] ; then
shutdown_guest_async " $uri " " $guest "
on_shutdown = " $on_shutdown $guest "
fi
2012-02-28 19:09:42 +04:00
done
sleep 1
2012-08-21 19:03:40 +04:00
set -- $guests
2020-03-29 13:44:43 +03:00
local guestcount = $#
2012-08-21 19:03:40 +04:00
set -- $on_shutdown
2020-03-29 13:44:43 +03:00
local shutdowncount = $#
2012-08-21 19:03:40 +04:00
2012-02-28 19:09:42 +04:00
if $check_timeout ; then
2012-08-21 19:03:40 +04:00
if [ $(( $timeout % 5 )) -eq 0 ] ; then
printf " $format " $(( $guestcount + $shutdowncount )) " $timeout "
fi
2012-02-28 19:09:42 +04:00
timeout = $(( $timeout - 1 ))
if [ $timeout -le 0 ] ; then
eval_gettext "Timeout expired while shutting down domains" ; echo
RETVAL = 1
return
fi
2012-08-21 19:03:40 +04:00
else
slept = $(( $slept + 1 ))
if [ $(( $slept % 5 )) -eq 0 ] ; then
printf " $format " $(( $guestcount + $shutdowncount ))
fi
2012-02-28 19:09:42 +04:00
fi
2012-08-21 19:03:40 +04:00
2020-03-29 13:44:43 +03:00
local on_shutdown_prev = $on_shutdown
2018-01-16 18:05:26 +03:00
check_guests_shutdown " $uri " " $on_shutdown "
on_shutdown = " $guests_shutting_down "
2012-02-28 19:09:42 +04:00
print_guests_shutdown " $uri " " $on_shutdown_prev " " $on_shutdown "
done
}
2012-02-28 16:58:59 +04:00
# stop
# Shutdown or save guests on the configured uris
2010-05-14 17:37:55 +04:00
stop( ) {
2020-03-29 13:44:43 +03:00
local suspending = true
local uri =
2010-05-14 17:37:55 +04:00
# last stop was not followed by start
2010-05-27 16:47:11 +04:00
[ -f " $LISTFILE " ] && return 0
2010-05-14 17:37:55 +04:00
2020-06-03 14:53:13 +03:00
if [ " x $ON_SHUTDOWN " = xshutdown ] ; then
2010-05-14 17:37:55 +04:00
suspending = false
2012-02-28 19:09:42 +04:00
if [ $SHUTDOWN_TIMEOUT -lt 0 ] ; then
gettext "SHUTDOWN_TIMEOUT must be equal or greater than 0"
2011-01-04 21:13:56 +03:00
echo
2010-05-14 17:37:55 +04:00
RETVAL = 6
return
fi
fi
2010-05-27 16:47:11 +04:00
: >" $LISTFILE "
2011-03-12 00:06:09 +03:00
set -f
2010-05-14 17:37:55 +04:00
for uri in $URIS ; do
2011-03-12 00:06:09 +03:00
set +f
2010-07-27 16:21:51 +04:00
2012-02-28 17:39:17 +04:00
test_connect " $uri " || continue
eval_gettext "Running guests on \$uri URI: "
2010-07-27 16:21:51 +04:00
2020-03-29 13:44:43 +03:00
local list = $( list_guests " $uri " )
2010-05-14 17:37:55 +04:00
if [ $? -eq 0 ] ; then
2020-03-29 13:44:43 +03:00
local empty = true
2010-05-14 17:37:55 +04:00
for uuid in $list ; do
2011-03-09 11:54:57 +03:00
" $empty " || printf ", "
printf %s " $( guest_name " $uri " " $uuid " ) "
2010-05-14 17:37:55 +04:00
empty = false
done
2012-02-28 17:32:21 +04:00
2011-03-09 11:54:57 +03:00
if " $empty " ; then
2012-02-28 17:32:21 +04:00
gettext "no running guests."
fi
echo
fi
if " $suspending " ; then
2020-03-29 13:44:43 +03:00
local transient = $( list_guests " $uri " "--transient" )
2012-02-28 17:32:21 +04:00
if [ $? -eq 0 ] ; then
2020-03-29 13:44:43 +03:00
local empty = true
local uuid =
2012-02-28 17:32:21 +04:00
for uuid in $transient ; do
if " $empty " ; then
eval_gettext "Not suspending transient guests on URI: \$uri: "
empty = false
else
printf ", "
fi
printf %s " $( guest_name " $uri " " $uuid " ) "
done
echo
# reload domain list to contain only persistent guests
list = $( list_guests " $uri " "--persistent" )
if [ $? -ne 0 ] ; then
eval_gettext "Failed to list persistent guests on \$uri"
echo
RETVAL = 1
set +f
return
fi
2010-05-14 17:37:55 +04:00
else
2012-02-28 17:32:21 +04:00
gettext "Failed to list transient guests"
2010-05-14 17:37:55 +04:00
echo
2012-02-28 17:32:21 +04:00
RETVAL = 1
set +f
return
2010-05-14 17:37:55 +04:00
fi
fi
2012-02-28 17:32:21 +04:00
if [ -n " $list " ] ; then
2016-10-07 10:56:32 +03:00
echo " $uri " $list >>" $LISTFILE "
2012-02-28 17:32:21 +04:00
fi
2010-05-14 17:37:55 +04:00
done
2011-03-12 00:06:09 +03:00
set +f
2010-05-14 17:37:55 +04:00
2012-05-15 12:22:28 +04:00
if [ -s " $LISTFILE " ] ; then
while read uri list; do
if " $suspending " ; then
eval_gettext "Suspending guests on \$uri URI..." ; echo
else
eval_gettext "Shutting down guests on \$uri URI..." ; echo
fi
2010-05-14 17:37:55 +04:00
2012-05-15 12:22:28 +04:00
if [ " $PARALLEL_SHUTDOWN " -gt 1 ] &&
! " $suspending " ; then
shutdown_guests_parallel " $uri " " $list "
else
2020-03-29 13:44:43 +03:00
local guest =
2012-05-15 12:22:28 +04:00
for guest in $list ; do
if " $suspending " ; then
suspend_guest " $uri " " $guest "
else
shutdown_guest " $uri " " $guest "
fi
done
fi
done <" $LISTFILE "
else
rm -f " $LISTFILE "
fi
2010-05-27 16:47:11 +04:00
rm -f " $VAR_SUBSYS_LIBVIRT_GUESTS "
2010-05-14 17:37:55 +04:00
}
2012-02-28 16:58:59 +04:00
# gueststatus
# List status of guests
2010-05-14 17:37:55 +04:00
gueststatus( ) {
2020-03-29 13:44:43 +03:00
local uri =
2011-03-12 00:06:09 +03:00
set -f
2010-05-14 17:37:55 +04:00
for uri in $URIS ; do
2011-03-12 00:06:09 +03:00
set +f
2010-05-14 17:37:55 +04:00
echo " * $uri URI: "
2016-10-07 10:56:33 +03:00
retval run_virsh " $uri " list | grep -v "Domain-0" || echo
2010-05-14 17:37:55 +04:00
done
2011-03-12 00:06:09 +03:00
set +f
2010-05-14 17:37:55 +04:00
}
2010-07-27 23:50:35 +04:00
# 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
2011-01-04 21:13:56 +03:00
gettext "stopped, with saved guests" ; echo
2010-07-27 23:50:35 +04:00
RETVAL = 3
else
if [ -f " $VAR_SUBSYS_LIBVIRT_GUESTS " ] ; then
2011-01-04 21:13:56 +03:00
gettext "started" ; echo
2013-04-30 15:44:33 +04:00
RETVAL = 0
2010-07-27 23:50:35 +04:00
else
2011-01-04 21:13:56 +03:00
gettext "stopped, with no saved guests" ; echo
2013-04-30 15:44:33 +04:00
RETVAL = 3
2010-07-27 23:50:35 +04:00
fi
fi
}
2010-07-27 22:05:27 +04:00
# usage [val]
# Display usage string, then exit with VAL (defaults to 2).
usage( ) {
2020-03-29 13:44:43 +03:00
local program_name = $0
2011-01-04 21:13:56 +03:00
eval_gettext "Usage: \$program_name {start|stop|status|restart|" \
"condrestart|try-restart|reload|force-reload|gueststatus|shutdown}" ; echo
2010-07-27 22:05:27 +04:00
exit ${ 1 -2 }
}
2010-05-14 17:37:55 +04:00
# See how we were called.
2010-07-27 22:05:27 +04:00
if test $# != 1; then
usage
fi
2010-05-14 17:37:55 +04:00
case " $1 " in
2010-07-27 22:05:27 +04:00
--help)
usage 0
; ;
2010-05-14 17:37:55 +04:00
start| stop| gueststatus)
2011-03-09 11:54:57 +03:00
" $1 "
2010-05-14 17:37:55 +04:00
; ;
restart)
stop && start
; ;
2010-07-27 22:21:31 +04:00
condrestart| try-restart)
[ -f " $VAR_SUBSYS_LIBVIRT_GUESTS " ] && stop && start
; ;
reload| force-reload)
# Nothing to do; we reread configuration on each invocation
2010-05-14 17:37:55 +04:00
; ;
status)
2010-07-27 23:50:35 +04:00
rh_status
2010-05-14 17:37:55 +04:00
; ;
shutdown)
ON_SHUTDOWN = shutdown
stop
; ;
*)
2010-07-27 22:05:27 +04:00
usage
2010-05-14 17:37:55 +04:00
; ;
esac
exit $RETVAL