remove unnecessary init.d, postint, postrm and qmupdate scripts

KVM modules are autoloaded with recent udev, and vhost_net can
be loaded with modules-load.d configuration
This commit is contained in:
Dietmar Maurer 2015-02-27 16:01:51 +01:00
parent 6b0ddb3cf4
commit 4841125d66
6 changed files with 8 additions and 346 deletions

View File

@ -4,6 +4,8 @@ VERSION=4.0
PACKAGE=qemu-server
PKGREL=1
CFLAGS= -O2 -Werror -Wall -Wtype-limits -Wl,-z,relro
DESTDIR=
PREFIX=/usr
BINDIR=${PREFIX}/bin
@ -32,15 +34,14 @@ dinstall: deb
control: control.in
sed -e s/@@VERSION@@/${VERSION}/ -e s/@@PKGRELEASE@@/${PKGREL}/ -e s/@@ARCH@@/${ARCH}/<$< >$@
vzsyscalls.ph: vzsyscalls.h
h2ph -d . vzsyscalls.h
vmtar: vmtar.c utils.c
gcc -O2 -Werror -Wall -Wtype-limits -o vmtar vmtar.c
gcc ${CFLAGS} -o vmtar vmtar.c
sparsecp: sparsecp.c utils.c
gcc -O2 -Werror -Wall -Wtype-limits -o sparsecp sparsecp.c
gcc ${CFLAGS} -o sparsecp sparsecp.c
%.1.gz: %.1.pod
rm -f $@
@ -62,7 +63,7 @@ qmrestore.1.pod: qmrestore
vm.conf.5.pod: gen-vmconf-pod.pl PVE/QemuServer.pm
perl -I. ./gen-vmconf-pod.pl >$@
PKGSOURCES=qm qm.1.gz qm.1.pod qmrestore qmrestore.1.pod qmrestore.1.gz qmextract sparsecp vmtar qemu.init.d qmupdate control vm.conf.5.pod vm.conf.5.gz
PKGSOURCES=qm qm.1.gz qm.1.pod qmrestore qmrestore.1.pod qmrestore.1.gz qmextract sparsecp vmtar control vm.conf.5.pod vm.conf.5.gz
.PHONY: install
install: ${PKGSOURCES}
@ -79,12 +80,11 @@ install: ${PKGSOURCES}
make -C PVE install
install -m 0755 qm ${DESTDIR}${SBINDIR}
install -m 0755 qmrestore ${DESTDIR}${SBINDIR}
install -D -m 0755 qmupdate ${DESTDIR}${VARLIBDIR}/qmupdate
install -D -m 0755 qemu.init.d ${DESTDIR}/etc/init.d/${PACKAGE}
install -m 0755 pve-bridge ${DESTDIR}${VARLIBDIR}/pve-bridge
install -m 0755 pve-bridgedown ${DESTDIR}${VARLIBDIR}/pve-bridgedown
install -s -m 0755 vmtar ${DESTDIR}${LIBDIR}
install -s -m 0755 sparsecp ${DESTDIR}${LIBDIR}
install -D -m 0644 modules-load.conf ${DESTDIR}/etc/modules-load.d/qemu-server.conf
install -m 0755 qmextract ${DESTDIR}${LIBDIR}
install -m 0644 qm.1.gz ${DESTDIR}/usr/share/man/man1/
install -m 0644 qm.1.pod ${DESTDIR}/${PODDIR}
@ -101,9 +101,7 @@ deb ${DEB}: ${PKGSOURCES}
perl -I. ./qm verifyapi
install -d -m 0755 build/DEBIAN
install -m 0644 control build/DEBIAN
install -m 0755 postinst build/DEBIAN
install -m 0755 postrm build/DEBIAN
echo "/etc/init.d/${PACKAGE}" >>build/DEBIAN/conffiles
echo "/etc/modules-load.d/qemu-server.conf" >>build/DEBIAN/conffiles
install -D -m 0644 copyright build/${DOCDIR}/${PACKAGE}/copyright
install -m 0644 changelog.Debian build/${DOCDIR}/${PACKAGE}/
gzip -9 build/${DOCDIR}/${PACKAGE}/changelog.Debian

1
modules-load.conf Normal file
View File

@ -0,0 +1 @@
vhost_net

View File

@ -1,48 +0,0 @@
#!/bin/sh
# postinst script for qemu-server
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
configure)
update-rc.d qemu-server defaults >/dev/null 2>&1
# update old config files
/var/lib/qemu-server/qmupdate
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

8
postrm
View File

@ -1,8 +0,0 @@
#! /bin/sh
# Abort if any command returns an error value
set -e
if [ "$1" = purge ]; then
update-rc.d qemu-server remove >/dev/null 2>&1
fi

View File

@ -1,46 +0,0 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: qemu-server
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start all qemu/kvm virtual machines
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PROG=/usr/sbin/qm
DESC="Qemu Server"
test -x $PROG || exit 0
set -e
case "$1" in
start)
(egrep '^flags.*svm' /proc/cpuinfo >/dev/null && modprobe -q kvm-amd) ||
(egrep '^flags.*vmx' /proc/cpuinfo >/dev/null && modprobe -q kvm-intel) ||
echo "unable to load kvm module"
modprobe -q vhost_net || true
# recent distributions use tmpfs for /var/run
# and /var/lock to avoid to clean it up on every boot.
# they also assume that init scripts will create
# required subdirectories for proper operations
mkdir -p /var/run/qemu-server
mkdir -p /var/lock/qemu-server
;;
stop)
# nothing to do, because we are no real daemon
;;
force-reload)
;;
restart)
# nothing to do, because we are no real daemon
;;
esac
exit 0

235
qmupdate
View File

@ -1,235 +0,0 @@
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
use Digest::SHA;
# script to upgrade V0.9.1 to V0.9.2 format
my $confvars_0_9_1 = {
onboot => 'bool',
autostart => 'bool',
reboot => 'bool',
cpulimit => 'natural',
cpuunits => 'natural',
hda => 'file',
hdb => 'file',
sda => 'file',
sdb => 'file',
cdrom => 'file',
memory => 'natural',
keyboard => 'lang',
name => 'string',
ostype => 'ostype',
boot => 'boot',
smp => 'natural',
acpi => 'bool',
network => 'network',
};
sub load_config_0_9_1 {
my ($vmid, $filename) = @_;
my $fh = new IO::File ($filename, "r") ||
return undef;
my $res = {};
while (my $line = <$fh>) {
next if $line =~ m/^\#/;
next if $line =~ m/^\s*$/;
if ($line =~ m/^([a-z]+):\s*(\S+)\s*$/) {
my $key = $1;
my $value = $2;
if (my $type = $confvars_0_9_1->{$key}) {
$res->{$key} = $value;
} else {
return undef; # unknown setting
}
}
}
return $res;
}
sub parse_network_0_9_1 {
my ($data) = @_;
my $res = {
type => 'tap',
};
foreach my $rec (split (/\s*,\s*/, $data)) {
if ($rec =~ m/^(tap|user)$/) {
$res->{type} = $rec;
} elsif ($rec =~ m/^model\s*=\s*(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)$/) {
$res->{model} = $1;
} elsif ($rec =~ m/macaddr\s*=\s*([0-9a-f:]+)/i) {
$res->{macaddr} = $1;
} else {
return undef;
}
}
return $res;
}
sub random_ether_addr {
my $rand = Digest::SHA::sha1_hex (rand(), time());
my $mac = '';
for (my $i = 0; $i < 6; $i++) {
my $ss = hex (substr ($rand, $i*2, 2));
if (!$i) {
$ss &= 0xfe; # clear multicast
$ss |= 2; # set local id
}
$ss = sprintf ("%02X", $ss);
if (!$i) {
$mac .= "$ss";
} else {
$mac .= ":$ss";
}
}
return $mac;
}
sub convert_0_9_1_to_0_9_2 {
my ($vmid, $cfile, $conf) = @_;
print "Upgrading VM $vmid to new format\n";
die "undefined vm id" if !$vmid || $vmid !~ m/^\d+$/;
my $dmap = {
hda => 'ide0',
hdb => 'ide1',
sda => 'scsi0',
sdb => 'scsi1',
};
my $tmpdir = "/var/lib/vz/images/$vmid.upgrade";
my $tmpconf = "$cfile.upgrade";
my $images = [];
eval {
mkdir $tmpdir || die "unable to create dir '$tmpdir'\n";
my $fh = new IO::File ($cfile, "r") ||
die "unable to read config for VM $vmid\n";
my $newfh = new IO::File ($tmpconf, "w") ||
die "unable to create file '$tmpconf'\n";
while (my $line = <$fh>) {
next if $line =~ m/^\#/;
next if $line =~ m/^\s*$/;
if ($line =~ m/^([a-z]+):\s*(\S+)\s*$/) {
my $key = $1;
my $value = $2;
if (my $type = $confvars_0_9_1->{$key}) {
if ($key eq 'network') {
my $onw = parse_network_0_9_1 ($value);
if ($onw && ($onw->{type} eq 'tap')) {
if (!$onw->{macaddr}) {
$onw->{macaddr} = random_ether_addr ();
}
print $newfh "vlan0: $onw->{model}=$onw->{macaddr}\n";
} elsif ($onw && ($onw->{type} eq 'user')) {
if (!$onw->{macaddr}) {
$onw->{macaddr} = random_ether_addr ();
}
print $newfh "vlanu: $onw->{model}=$onw->{macaddr}\n";
} else {
die "unable to convert network specification\n";
}
} elsif ($key eq 'cdrom') {
$value =~ s|^/.*/||;
print $newfh "ide2: $value,media=cdrom\n";
} elsif (defined ($dmap->{$key})) {
if ($value =~ m|^/var/lib/vz/images/([^/]+)$|) {
$value = $1;
} elsif ($value !~ m|/|) {
# no nothing
} else {
die "wrong image path";
}
link "/var/lib/vz/images/$value", "$tmpdir/$value";
(-f "$tmpdir/$value") ||
die "unable to create image link\n";
push @$images, $value;
print $newfh "$dmap->{$key}: $value\n";
} else {
print $newfh "$key: $value\n";
}
} else {
die "unknown setting '$key'\n";
}
}
}
if ($conf->{hda}) {
print $newfh "bootdisk: ide0\n";
} elsif ($conf->{hdb}) {
print $newfh "bootdisk: ide1\n";
} elsif ($conf->{sda}) {
print $newfh "bootdisk: scsi0\n";
} elsif ($conf->{sdb}) {
print $newfh "bootdisk: scsi1\n";
}
};
my $err = $@;
if ($err) {
system ("rm -rf $tmpdir $tmpconf");
} else {
if (!rename $tmpdir, "/var/lib/vz/images/$vmid") {
system ("rm -rf $tmpdir $tmpconf");
die "commiting '/var/lib/vz/images/$vmid' failed - $!\n";
}
if (!rename $tmpconf, $cfile) {
system ("rm -rf /var/lib/vz/images/$vmid $tmpconf");
die "commiting new configuration '$cfile' failed - $!\n";
}
foreach my $img (@$images) {
unlink "/var/lib/vz/images/$img";
}
}
die $err if $err;
}
foreach my $vmconf (</etc/qemu-server/*.conf>) {
next if $vmconf !~ m|/etc/qemu-server/(\d+)\.conf|;
my $vmid = $1;
next if -d "/var/lib/vz/images/$vmid"; # already new format
eval {
my $res = load_config_0_9_1 ($vmid, $vmconf);
if ($res && ($res->{network} || $res->{hda} || $res->{hdb} ||
$res->{sda} || $res->{sda} || $res->{cdrom})) {
convert_0_9_1_to_0_9_2 ($vmid, $vmconf, $res);
}
};
warn $@ if $@;
}
exit 0;