Skip to contentSkip to conversation

EL6 initscript feedback.

DISCUSSION Steven Haigh 4 participants 8 messages May 21, 2013

lore
Share & tools
lore
#0 lore raw

Hi all,

I'm throwing in my initscript here that I've been pushing to autostart xen domains on system boot.

There are at least one issue right now that I'm not 100% sure how to handle - and that is domains created by libvirt. These continue to show in an xm/xl list output even when they are not paused / running / blocked - causing my initscript to think they are still running.

The ways I can think of detecting this are *very* hacky and I wouldn't feel comfortable to including them in widely used packages.

I'm wondering if people have some spare time that they review the logic in this initscript and provide feedback / suggestions / fixes / improvements that I can roll into the scripts to enhance them for all.

Thanks.

Signature · 6 lines
Steven Haigh

Email: [email protected]
Web: https://www.crc.id.au
Phone: (03) 9001 6090 - 0412 935 897
Fax: (03) 8338 0299

#!/bin/bash
#

# /etc/init.d/xendomains
# Start / stop domains automatically when domain 0 boots / shuts down.
#
# chkconfig: 345 99 00
# description: Start / stop Xen domains.
#
# Re-written from scratch by Steven Haigh <[email protected]> for EL6 as stock
# script has a lot of problems. May work on other distros, YMMV.
#
### BEGIN INIT INFO
# Provides:          xendomains
# Required-Start:    $syslog $remote_fs xenstored xenconsoled
# Should-Start:      xend
# Required-Stop:     $syslog $remote_fs xenstored xenconsoled
# Should-Stop:       xend
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop secondary xen domains
# Description:       Start / stop domains automatically when domain 0 
#                    boots / shuts down.
### END INIT INFO

## Check if Xend is running, if so, use xm, else xl. XEND=pidof -x xend
if [ $? -eq 0 ]; then
CMD=which xm
else
CMD=which xl
fi

## Check to see if we're running as Dom0. If so, the following file should ## exist.
if ! [ -e /proc/xen/privcmd ]; then
echo "Not running as Domain0. Exiting..."
exit 0
fi

## Load the xendomains options, bailing if we can't.
if [ -r /etc/sysconfig/xendomains ]; then
. /etc/sysconfig/xendomains
else
echo "/etc/sysconfig/xendomains not found or unreadable. This is an issue. Exiting..." exit 0
fi

if [ -d /var/lock/subsys ]; then
LOCKFILE=/var/lock/subsys/xendomains
else
LOCKFILE=/var/lock/xendomains
fi

## Source function library.
. /etc/init.d/functions

get_domu_name() {
    DOMU_NAME=$(awk '/^name/ {print $3}' $1)
}
watchdog() {
	## Launch a command and wait until the timeout before killing forcefully.
	for WAIT in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
		RESULT=`ps -p $PID`
		if [ $? -eq 1 ]; then
			success; echo
			break
		fi
		echo -n "."
		sleep 1
	done
	RESULT=`ps -p $PID`
	if [ $? -eq 0 ]; then
		warning; echo
		kill $PID
	fi
	echo
}

start() {
touch $LOCKFILE

## Check to see if we should restore saved DomUs on start
## Also check if the restore directory actually exists.
if [ "$XENDOMAINS_RESTORE" = "true" ] && [ -d $XENDOMAINS_SAVE ] && [ -n "$XENDOMAINS_SAVE" ]; then
for DOMU in $XENDOMAINS_SAVE/*; do
if [ -r $DOMU ]; then
HEADER=head -c 16 $DOMU | head -n 1 2> /dev/null
if [ "$HEADER" = "LinuxGuestRecord" ] || [ "$HEADER" = "Xen saved domain" ]; then
echo -n "Restoring Xen Domain ${DOMU##*/}"
RESULT=$CMD restore $DOMU 2>&1 1>/dev/null
if [ $? -ne 0 ]; then
failure; echo
else
success; echo
fi
rm -f "$DOMU"
fi
fi
done
fi

## Check to see if our autostart directory exists and is actually set. if [ -d $XENDOMAINS_AUTO ] && [ -n $XENDOMAINS_AUTO ]; then
## Start each domain in our autostart directory. for DOMU in $XENDOMAINS_AUTO/*; do
get_domu_name $DOMU
echo -n $"Starting Xen auto domain $DOMU_NAME: "

## Check if domain is already running. RESULT=$CMD list $DOMU_NAME >& /dev/null if [ $? -eq 0 ] && [ $? -ne 2 ]; then
## DomU is already running. echo -n " (Skipped - Already running)"
else
## Start the DomU... RESULT=$CMD create $DOMU >& /dev/null if [ $? -eq 0 ]; then
usleep $XENDOMAINS_CREATE_USLEEP success; echo
else
failure; echo
fi
fi
done
fi

return 0
}

stop() {
## Check to see if we should send a SysRq to the DomUs if [ -n "$XENDOMAINS_SYSRQ" ]; then
IFS=$'\n'
echo -n "Sending SYSRQs to Xen Domains:" for DOMU in $CMD list | tail -n +3 | sort; do
unset IFS
DOMU_NAME=echo "$DOMU" | awk '{ print $1 }' for sysrq in $XENDOMAINS_SYSRQ; do
$CMD sysrq $DOMU_NAME $sysrq echo -n "."
done
done
success; echo
fi

## Check to see if we should migrate running domains...
if [ -n "$XENDOMAINS_MIGRATE" ]; then
## We should be doing a migrate. We don't really do much, just pass the ## values to XM/XL - if it fails, save or shutdown can have a go. IFS=$'\n'
for DOMU in $CMD list | tail -n +3 | sort; do
unset IFS
DOMU_NAME=echo "$DOMU" | awk '{ print $1 }' echo -n "Migrating Xen domain $DOMU_NAME: "
$CMD migrate $DOMU_NAME $XENDOMAINS_MIGRATE 2>&1 1>/dev/null & PID=$!
watchdog
done
fi

## Check to see if we are to save domains...
if [ -d $XENDOMAINS_SAVE ] && [ -n "$XENDOMAINS_SAVE" ]; then
## Cycle through the domains running and do what we need to do. IFS=$'\n'
for DOMU in $CMD list | tail -n +3 | sort; do
unset IFS
DOMU_NAME=echo "$DOMU" | awk '{ print $1 }'

## Now we set our ionice to lower than realtime as we don't want the ## system to become unresponsive while saving a DomU. It still may ## need to fulfil requests from other DomUs etc. ionice -c 2 -n 7 -p $$

echo -n "Saving Xen Domain $DOMU_NAME: "
$CMD save $DOMU_NAME $XENDOMAINS_SAVE/$DOMU_NAME > /dev/null 2>&1 & PID=$!
watchdog
done
fi

## Shut down the remaining domains...
if [ -n "$XENDOMAINS_SHUTDOWN" ]; then
if [ "$CMD" = which xm ]; then
echo -n "Sending shutdown to all DomUs: " $CMD shutdown --all
success; echo
else
IFS=$'\n'
for DOMU in $CMD list | tail -n +3 | sort; do
unset IFS
DOMU_NAME=echo "$DOMU" | awk '{ print $1 }' echo -n "Sending shutdown to DomU $DOMU_NAME:" $CMD shutdown -F "$DOMU_NAME" success; echo
done
fi

echo "Waiting for all DomUs to complete shutdown" for WAIT in seq 0 $XENDOMAINS_STOP_MAXWAIT; do
echo -n "."
## Check to see how many guests are still running. NUM_DOMU=$(($CMD list | wc -l-2))
if [ $NUM_DOMU -eq "0" ]; then
success; echo
break
fi
sleep 1
done

## Look for stray DomUs
NUM_DOMU=$(($CMD list | wc -l-2))
if [ $NUM_DOMU -ne "0" ]; then
## Forcefully close any remaining DomUs warning; echo
IFS=$'\n'
for DOMU in $CMD list | tail -n +3 | sort; do
unset IFS
DOMU_NAME=echo "$DOMU" | awk '{ print $1 }' ID=echo "$DOMU" | awk '{ print $2 }' if [ -n "$ID" ]; then
echo -n "Forcefully destroying $DOMU_NAME:" $CMD destroy $DOMU_NAME 2>&1 1>/dev/null & success; echo
fi
done
fi
fi

rm -f $LOCKFILE
return 0
}

status() {
## We've already passed the test to see if Xen Dom0 is running, so here ## we check the number of lines returned from a list command and minus ## 2 from it (Header + Domain-0) and also some memory stats. NUM_DOMU=$(($CMD list | wc -l-2))
MEM_FREE=$CMD info | grep free_memory | cut -f2 -d":" MEM_TOTAL=$CMD info | grep total_memory | cut -f2 -d":"
echo "Xen running with $NUM_DOMU DomUs. $MEM_FREE MB of$MEM_TOTAL MB free." return 0
}

case "$1" in

    start)
        start
        RETVAL=$?
        ;;
    stop)
        stop
        RETVAL=$?
        ;;
    status)
        status
        RETVAL=$?
        ;;
    restart)
	stop
	start
	;;

esac

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw
Quoted 10 lines · Steven Haigh

Hi all,

I'm throwing in my initscript here that I've been pushing to autostart xen domains on system boot.

There are at least one issue right now that I'm not 100% sure how to handle - and that is domains created by libvirt. These continue to show in an xm/xl list output even when they are not paused / running / blocked - causing my initscript to think they are still running.

Quoted 6 lines

The ways I can think of detecting this are *very* hacky and I wouldn't feel comfortable to including them in widely used packages.

I'm wondering if people have some spare time that they review the logic in this initscript and provide feedback / suggestions / fixes / improvements that I can roll into the scripts to enhance them for all.

Is it actually a good idea to mix and match different toolstacks on the same host? If somebody intends to use libvirt, surely she would want to use it for everything?

#2 lore raw
Quoted 14 lines · Stefano Stabellini
Quoted 13 lines · Steven Haigh

Hi all,

I'm throwing in my initscript here that I've been pushing to autostart xen domains on system boot.

There are at least one issue right now that I'm not 100% sure how to handle - and that is domains created by libvirt. These continue to show in an xm/xl list output even when they are not paused / running / blocked - causing my initscript to think they are still running.

The ways I can think of detecting this are *very* hacky and I wouldn't feel comfortable to including them in widely used packages.

Quoted 7 lines
Quoted 3 lines

I'm wondering if people have some spare time that they review the logic in this initscript and provide feedback / suggestions / fixes / improvements that I can roll into the scripts to enhance them for all.

Is it actually a good idea to mix and match different toolstacks on the same host? If somebody intends to use libvirt, surely she would want to use it for everything?

This is the interesting question... which probably leads into a more important question... What is the best practices for config management and defining configuration for DomU's?

While I recommend that people use a plain text config file in /etc/xen (although really the files can be just about anywhere) and then links to various auto-start DomU's in /etc/xen/auto as a general rule.

Am I correct in thinking that libvirt only keeps details of domains in the xenstore? Is this recommended? Although more a libvirt question - can libvirt be configured to use config files in /etc/xen or similar?

Signature · 6 lines
Steven Haigh

Email: [email protected]
Web: https://www.crc.id.au
Phone: (03) 9001 6090 - 0412 935 897
Fax: (03) 8338 0299
#3 lore raw
Quoted 32 lines · Steven Haigh
Quoted 14 lines · Stefano Stabellini
Quoted 13 lines · Steven Haigh

Hi all,

I'm throwing in my initscript here that I've been pushing to autostart xen domains on system boot.

There are at least one issue right now that I'm not 100% sure how to handle - and that is domains created by libvirt. These continue to show in an xm/xl list output even when they are not paused / running / blocked - causing my initscript to think they are still running.

The ways I can think of detecting this are *very* hacky and I wouldn't feel comfortable to including them in widely used packages.

Quoted 7 lines
Quoted 3 lines

I'm wondering if people have some spare time that they review the logic in this initscript and provide feedback / suggestions / fixes / improvements that I can roll into the scripts to enhance them for all.

Is it actually a good idea to mix and match different toolstacks on the same host? If somebody intends to use libvirt, surely she would want to use it for everything?

This is the interesting question... which probably leads into a more important question... What is the best practices for config management and defining configuration for DomU's?

While I recommend that people use a plain text config file in /etc/xen (although really the files can be just about anywhere) and then links to various auto-start DomU's in /etc/xen/auto as a general rule.

Quoted 4 lines

Am I correct in thinking that libvirt only keeps details of domains in the xenstore? Is this recommended? Although more a libvirt question
- can libvirt be configured to use config files in /etc/xen or similar?

I think this is largely distribution dependant. In the case of EL/Fedora, libvirt seems to be the distro's intended way of managing VMs, at least for their primary supported virtualization method (KVM).

In the interest of clarity and maintainability I have seen the light and converted my VMs to simple text files in /etc/xen/ (there seems to be no documentation on how to edit most of the settings in xenstore). Some consensus on the best way would be good, though.

Gordan

#4 lore raw
Quoted 45 lines · Gordan Bobic
Quoted 39 lines · Steven Haigh
Quoted 25 lines · Stefano Stabellini
Quoted 18 lines · Steven Haigh

Hi all,

I'm throwing in my initscript here that I've been pushing to autostart xen
domains on system boot.

There are at least one issue right now that I'm not 100% sure how to handle -
and that is domains created by libvirt. These continue to show in an xm/xl
list output even when they are not paused / running / blocked - causing my
initscript to think they are still running.

The ways I can think of detecting this are *very* hacky and I wouldn't feel
comfortable to including them in widely used packages.

Quoted 5 lines

I'm wondering if people have some spare time that they review the logic in
this initscript and provide feedback / suggestions / fixes / improvements that
I can roll into the scripts to enhance them for all.

Quoted 3 lines

Is it actually a good idea to mix and match different toolstacks on the same host? If somebody intends to use libvirt, surely she would want to use it for everything?

This is the interesting question... which probably leads into a more important question... What is the best practices for config management and defining configuration for DomU's?

While I recommend that people use a plain text config file in /etc/xen (although really the files can be just about anywhere) and then links to various auto-start DomU's in /etc/xen/auto as a general rule.

Quoted 4 lines

Am I correct in thinking that libvirt only keeps details of domains in the xenstore? Is this recommended? Although more a libvirt question
- can libvirt be configured to use config files in /etc/xen or similar?

Quoted 8 lines

I think this is largely distribution dependant. In the case of EL/Fedora, libvirt seems to be the distro's intended way of managing VMs, at least for their primary supported virtualization method (KVM).

In the interest of clarity and maintainability I have seen the light and converted my VMs to simple text files in /etc/xen/ (there seems to be no documentation on how to edit most of the settings in xenstore). Some consensus on the best way would be good, though.

I think that using simple text files in /etc/xen for VM configs is clearly the right way to go from the Xen POV.

#5 lore raw
Quoted 50 lines · Stefano Stabellini
Quoted 49 lines · Gordan Bobic
Quoted 39 lines · Steven Haigh
Quoted 25 lines · Stefano Stabellini
Quoted 18 lines · Steven Haigh

Hi all,

I'm throwing in my initscript here that I've been pushing to autostart xen
domains on system boot.

There are at least one issue right now that I'm not 100% sure how to handle -
and that is domains created by libvirt. These continue to show in an xm/xl
list output even when they are not paused / running / blocked - causing my
initscript to think they are still running.

The ways I can think of detecting this are *very* hacky and I wouldn't feel
comfortable to including them in widely used packages.

Quoted 5 lines

I'm wondering if people have some spare time that they review the logic in
this initscript and provide feedback / suggestions / fixes / improvements that
I can roll into the scripts to enhance them for all.

Quoted 3 lines

Is it actually a good idea to mix and match different toolstacks on the same host? If somebody intends to use libvirt, surely she would want to use it for everything?

This is the interesting question... which probably leads into a more important question... What is the best practices for config management and defining configuration for DomU's?

While I recommend that people use a plain text config file in /etc/xen (although really the files can be just about anywhere) and then links to various auto-start DomU's in /etc/xen/auto as a general rule.

Quoted 4 lines

Am I correct in thinking that libvirt only keeps details of domains in the xenstore? Is this recommended? Although more a libvirt question
- can libvirt be configured to use config files in /etc/xen or similar?

I think this is largely distribution dependant. In the case of EL/Fedora, libvirt seems to be the distro's intended way of managing VMs, at least for their primary supported virtualization method (KVM).

Quoted 8 lines
Quoted 4 lines

In the interest of clarity and maintainability I have seen the light and converted my VMs to simple text files in /etc/xen/ (there seems to be no documentation on how to edit most of the settings in xenstore). Some consensus on the best way would be good, though.

I think that using simple text files in /etc/xen for VM configs is clearly the right way to go from the Xen POV.

Earlier libvirt versions, such as the default version in rhel5/centos5, creates /etc/xen/<vm> text files upon VM creation. Later libvirt versions changed the model to use xend managed domains with libvirt xml configs.

I wonder if that behaviour could be changed with some config option.. would be nice.

Also to convert from libvirt xml to xen text files you can use this:

virsh dumpxml vm_name > /tmp/a
virsh domxml-to-native xen-xm /tmp/a > /etc/xen/vm_name

Works for me on centos6 Xen (libvirt 0.10.2).

-- Pasi

#6 lore raw
Quoted 64 lines · Pasi Kärkkäinen
Quoted 50 lines · Stefano Stabellini
Quoted 49 lines · Gordan Bobic
Quoted 39 lines · Steven Haigh
Quoted 25 lines · Stefano Stabellini
Quoted 18 lines · Steven Haigh

Hi all,

I'm throwing in my initscript here that I've been pushing to autostart xen
domains on system boot.

There are at least one issue right now that I'm not 100% sure how to handle -
and that is domains created by libvirt. These continue to show in an xm/xl
list output even when they are not paused / running / blocked - causing my
initscript to think they are still running.

The ways I can think of detecting this are *very* hacky and I wouldn't feel
comfortable to including them in widely used packages.

Quoted 5 lines

I'm wondering if people have some spare time that they review the logic in
this initscript and provide feedback / suggestions / fixes / improvements that
I can roll into the scripts to enhance them for all.

Quoted 3 lines

Is it actually a good idea to mix and match different toolstacks on the same host? If somebody intends to use libvirt, surely she would want to use it for everything?

This is the interesting question... which probably leads into a more important question... What is the best practices for config management and defining configuration for DomU's?

While I recommend that people use a plain text config file in /etc/xen (although really the files can be just about anywhere) and then links to various auto-start DomU's in /etc/xen/auto as a general rule.

Quoted 4 lines

Am I correct in thinking that libvirt only keeps details of domains in the xenstore? Is this recommended? Although more a libvirt question
- can libvirt be configured to use config files in /etc/xen or similar?

I think this is largely distribution dependant. In the case of EL/Fedora, libvirt seems to be the distro's intended way of managing VMs, at least for their primary supported virtualization method (KVM).

Quoted 8 lines
Quoted 4 lines

In the interest of clarity and maintainability I have seen the light and converted my VMs to simple text files in /etc/xen/ (there seems to be no documentation on how to edit most of the settings in xenstore). Some consensus on the best way would be good, though.

I think that using simple text files in /etc/xen for VM configs is clearly the right way to go from the Xen POV.

Earlier libvirt versions, such as the default version in rhel5/centos5, creates /etc/xen/<vm> text files upon VM creation. Later libvirt versions changed the model to use xend managed domains with libvirt xml configs.

Quoted 8 lines

I wonder if that behaviour could be changed with some config option.. would be nice.

Also to convert from libvirt xml to xen text files you can use this:

virsh dumpxml vm_name > /tmp/a
virsh domxml-to-native xen-xm /tmp/a > /etc/xen/vm_name

Works for me on centos6 Xen (libvirt 0.10.2).

EL6 seems to keep the VM configs in xenstore, not in xml files.

Gordan

#7 lore raw
Quoted 67 lines · Gordan Bobic
Quoted 66 lines · Pasi Kärkkäinen
Quoted 50 lines · Stefano Stabellini
Quoted 49 lines · Gordan Bobic
Quoted 39 lines · Steven Haigh
Quoted 25 lines · Stefano Stabellini
Quoted 18 lines · Steven Haigh

Hi all,

I'm throwing in my initscript here that I've been pushing to autostart xen
domains on system boot.

There are at least one issue right now that I'm not 100% sure how to handle -
and that is domains created by libvirt. These continue to show in an xm/xl
list output even when they are not paused / running / blocked - causing my
initscript to think they are still running.

The ways I can think of detecting this are *very* hacky and I wouldn't feel
comfortable to including them in widely used packages.

Quoted 5 lines

I'm wondering if people have some spare time that they review the logic in
this initscript and provide feedback / suggestions / fixes / improvements that
I can roll into the scripts to enhance them for all.

Quoted 3 lines

Is it actually a good idea to mix and match different toolstacks on the same host? If somebody intends to use libvirt, surely she would want to use it for everything?

This is the interesting question... which probably leads into a more important question... What is the best practices for config management and defining configuration for DomU's?

While I recommend that people use a plain text config file in /etc/xen (although really the files can be just about anywhere) and then links to various auto-start DomU's in /etc/xen/auto as a general rule.

Quoted 4 lines

Am I correct in thinking that libvirt only keeps details of domains in the xenstore? Is this recommended? Although more a libvirt question
- can libvirt be configured to use config files in /etc/xen or similar?

I think this is largely distribution dependant. In the case of EL/Fedora, libvirt seems to be the distro's intended way of managing VMs, at least for their primary supported virtualization method (KVM).

Quoted 8 lines
Quoted 4 lines

In the interest of clarity and maintainability I have seen the light and converted my VMs to simple text files in /etc/xen/ (there seems to be no documentation on how to edit most of the settings in xenstore). Some consensus on the best way would be good, though.

I think that using simple text files in /etc/xen for VM configs is clearly the right way to go from the Xen POV.

Earlier libvirt versions, such as the default version in rhel5/centos5, creates /etc/xen/<vm> text files upon VM creation. Later libvirt versions changed the model to use xend managed domains with libvirt xml configs.

I wonder if that behaviour could be changed with some config option.. would be nice.

Quoted 9 lines
Quoted 6 lines

Also to convert from libvirt xml to xen text files you can use this:

virsh dumpxml vm_name > /tmp/a
virsh domxml-to-native xen-xm /tmp/a > /etc/xen/vm_name

Works for me on centos6 Xen (libvirt 0.10.2).

EL6 seems to keep the VM configs in xenstore, not in xml files.

EL6 doesn't ship with Xen, so it's good to mention which 3rdparty Xen/libvirt rpms you're using.

Anyway, with Centos6 Xen/libvirt rpms, when I install a new Xen VM with virt-install, it shows up in "virsh list", and also as a xend managed domain in "xm list", and I can use the libvirt "virsh dumpxml" and "virsh domxml-to-native xen-xm" commands to generate a normal xen text cfgfile for the VM.

-- Pasi