From d66d46a6eda2bb96f7ad70bde822496c5e8654c3 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 12 Jan 2014 13:39:28 +0000 Subject: [PATCH] migrate lxc container to ganeti git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@306 191e9f34-6774-4a6d-acfc-7664dacd4a2a --- recepies/ganeti/migrate-lxc/0-ganeti.sh | 14 +++++++++ recepies/ganeti/migrate-lxc/0-host.sh | 9 ++++++ recepies/ganeti/migrate-lxc/0-lxc.sh | 9 ++++++ .../migrate-lxc/1-inspect-container-ip.sh | 5 +++ .../ganeti/migrate-lxc/2-lxc-mount-point.sh | 15 +++++++++ .../ganeti/migrate-lxc/3-ganeti-root-lvm.sh | 15 +++++++++ .../migrate-lxc/4-lxc-snapshot-create.sh | 10 ++++++ .../migrate-lxc/5-lxc-rsync-snapshot.sh | 6 ++++ .../migrate-lxc/6-lxc-snapshot-remove.sh | 10 ++++++ .../migrate-lxc/7-lxc-stop-container.sh | 10 ++++++ .../ganeti/migrate-lxc/A-ganeti-fix-root.sh | 11 +++++++ .../B-ganeti-network-interfaces.sh | 31 +++++++++++++++++++ recepies/ganeti/migrate-lxc/C-ganeti-swap.sh | 10 ++++++ .../migrate-lxc/D-ganeti-create-instance.sh | 12 +++++++ .../migrate-lxc/E-ganeti-network-local.sh | 6 ++++ recepies/ganeti/migrate-lxc/F-ganeti-drdb.sh | 6 ++++ recepies/ganeti/migrate-lxc/G-ganeti-start.sh | 6 ++++ .../ganeti/migrate-lxc/H-host-configure.sh | 13 ++++++++ 18 files changed, 198 insertions(+) create mode 100644 recepies/ganeti/migrate-lxc/0-ganeti.sh create mode 100644 recepies/ganeti/migrate-lxc/0-host.sh create mode 100644 recepies/ganeti/migrate-lxc/0-lxc.sh create mode 100755 recepies/ganeti/migrate-lxc/1-inspect-container-ip.sh create mode 100755 recepies/ganeti/migrate-lxc/2-lxc-mount-point.sh create mode 100755 recepies/ganeti/migrate-lxc/3-ganeti-root-lvm.sh create mode 100755 recepies/ganeti/migrate-lxc/4-lxc-snapshot-create.sh create mode 100755 recepies/ganeti/migrate-lxc/5-lxc-rsync-snapshot.sh create mode 100755 recepies/ganeti/migrate-lxc/6-lxc-snapshot-remove.sh create mode 100755 recepies/ganeti/migrate-lxc/7-lxc-stop-container.sh create mode 100755 recepies/ganeti/migrate-lxc/A-ganeti-fix-root.sh create mode 100755 recepies/ganeti/migrate-lxc/B-ganeti-network-interfaces.sh create mode 100755 recepies/ganeti/migrate-lxc/C-ganeti-swap.sh create mode 100755 recepies/ganeti/migrate-lxc/D-ganeti-create-instance.sh create mode 100755 recepies/ganeti/migrate-lxc/E-ganeti-network-local.sh create mode 100755 recepies/ganeti/migrate-lxc/F-ganeti-drdb.sh create mode 100755 recepies/ganeti/migrate-lxc/G-ganeti-start.sh create mode 100755 recepies/ganeti/migrate-lxc/H-host-configure.sh diff --git a/recepies/ganeti/migrate-lxc/0-ganeti.sh b/recepies/ganeti/migrate-lxc/0-ganeti.sh new file mode 100644 index 0000000..12294ad --- /dev/null +++ b/recepies/ganeti/migrate-lxc/0-ganeti.sh @@ -0,0 +1,14 @@ +#master=`ssh root@10.60.0.112 gnt-cluster getmaster` +#if [ -z "$master" ] ; then +# echo "Ganeti master not found" +# exit 1 +#fi + +master=10.60.0.112 + +test -d ganeti || mkdir ganeti + +ssh_master() { + log=`basename $1` + ssh root@$master $* | tee ganeti/$log +} diff --git a/recepies/ganeti/migrate-lxc/0-host.sh b/recepies/ganeti/migrate-lxc/0-host.sh new file mode 100644 index 0000000..7132203 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/0-host.sh @@ -0,0 +1,9 @@ +export host_fqdn=rt.knjiznica.ffzg.hr +export host=`echo $host_fqdn | cut -d. -f1` +test -d $host || mkdir $host + +ssh_host() { + log=`basename $1` + ssh root@$host $* | tee $host/$log +} + diff --git a/recepies/ganeti/migrate-lxc/0-lxc.sh b/recepies/ganeti/migrate-lxc/0-lxc.sh new file mode 100644 index 0000000..523da2f --- /dev/null +++ b/recepies/ganeti/migrate-lxc/0-lxc.sh @@ -0,0 +1,9 @@ +export lxc=prod + +test -d lxc || mkdir lxc + +ssh_lxc() { + log=`basename $1` + ssh root@$lxc $* | tee lxc/$log +} + diff --git a/recepies/ganeti/migrate-lxc/1-inspect-container-ip.sh b/recepies/ganeti/migrate-lxc/1-inspect-container-ip.sh new file mode 100755 index 0000000..b80a85a --- /dev/null +++ b/recepies/ganeti/migrate-lxc/1-inspect-container-ip.sh @@ -0,0 +1,5 @@ +#!/bin/sh -x + +. ./0-host.sh + +ssh $host /sbin/ifconfig | tee $host/ifconfig diff --git a/recepies/ganeti/migrate-lxc/2-lxc-mount-point.sh b/recepies/ganeti/migrate-lxc/2-lxc-mount-point.sh new file mode 100755 index 0000000..ebb3a21 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/2-lxc-mount-point.sh @@ -0,0 +1,15 @@ +#!/bin/sh -x + +. ./0-host.sh +. ./0-lxc.sh + +ssh_lxc() { + log=`basename $1` + ssh root@$lxc $* | tee $host/$log +} + +ssh_lxc /etc/init.d/lxc-watchdog status +mnt=`cat $host/lxc-watchdog | grep ^$host | awk '{ print $4 }' | tee $host/mnt` +ssh_lxc df -h $mnt +size=`cat $host/df | grep /mnt/rt | awk '{ print $2 }' | tee $host/size` + diff --git a/recepies/ganeti/migrate-lxc/3-ganeti-root-lvm.sh b/recepies/ganeti/migrate-lxc/3-ganeti-root-lvm.sh new file mode 100755 index 0000000..e1d5b41 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/3-ganeti-root-lvm.sh @@ -0,0 +1,15 @@ +#!/bin/sh -x + +. ./0-host.sh +. ./0-ganeti.sh + + +ssh_master lvcreate --size `cat $host/size` --name $host ffzgvg + +ssh_master parted -s /dev/mapper/ffzgvg-$host 'mklabel msdos mkpart primary 0% 100% set 1 boot on' + +ssh_master mkfs.ext4 -L root /dev/mapper/ffzgvg-${host}p1 + +ssh_master mkdir /tmp/$host +ssh_master mount /dev/mapper/ffzgvg-${host}p1 /tmp/$host +ssh_master df -h /tmp/$host diff --git a/recepies/ganeti/migrate-lxc/4-lxc-snapshot-create.sh b/recepies/ganeti/migrate-lxc/4-lxc-snapshot-create.sh new file mode 100755 index 0000000..fd2f928 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/4-lxc-snapshot-create.sh @@ -0,0 +1,10 @@ +#!/bin/sh -x + +. ./0-host.sh +. ./0-lxc.sh + +ssh_lxc lvcreate -s -L 1G -n ganeti-$host /dev/raid5/$host +ssh_lxc mkdir /tmp/ganeti-$host +ssh_lxc mount /dev/raid5/ganeti-$host /tmp/ganeti-$host +ssh_lxc df -h /tmp/ganeti-$host + diff --git a/recepies/ganeti/migrate-lxc/5-lxc-rsync-snapshot.sh b/recepies/ganeti/migrate-lxc/5-lxc-rsync-snapshot.sh new file mode 100755 index 0000000..ef11fbb --- /dev/null +++ b/recepies/ganeti/migrate-lxc/5-lxc-rsync-snapshot.sh @@ -0,0 +1,6 @@ +#!/bin/sh -x + +. ./0-host.sh +. ./0-lxc.sh + +ssh_lxc rsync -ravH --numeric-ids --sparse --delete --exclude /tmp --exclude /var/tmp /tmp/ganeti-$host/ 10.60.0.112:/tmp/$host/ diff --git a/recepies/ganeti/migrate-lxc/6-lxc-snapshot-remove.sh b/recepies/ganeti/migrate-lxc/6-lxc-snapshot-remove.sh new file mode 100755 index 0000000..b19921f --- /dev/null +++ b/recepies/ganeti/migrate-lxc/6-lxc-snapshot-remove.sh @@ -0,0 +1,10 @@ +#!/bin/sh -x + +. ./0-host.sh +. ./0-lxc.sh + +ssh_lxc umount /tmp/ganeti-$host +ssh_lxc dmsetup remove raid5-ganeti--$host-cow +ssh_lxc dmsetup remove raid5-ganeti--$host +ssh_lxc lvremove /dev/raid5/ganeti-$host + diff --git a/recepies/ganeti/migrate-lxc/7-lxc-stop-container.sh b/recepies/ganeti/migrate-lxc/7-lxc-stop-container.sh new file mode 100755 index 0000000..6e7ab64 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/7-lxc-stop-container.sh @@ -0,0 +1,10 @@ +#!/bin/sh -x + +. ./0-host.sh +. ./0-lxc.sh + +ssh_lxc /etc/init.d/lxc-watchdog stop $host + +ssh_lxc rm -v /var/lib/lxc/$host/on_boot + +ssh_lxc rsync -ravH --numeric-ids --sparse --delete --exclude /tmp --exclude /var/tmp /mnt/$host/ 10.60.0.112:/tmp/$host/ diff --git a/recepies/ganeti/migrate-lxc/A-ganeti-fix-root.sh b/recepies/ganeti/migrate-lxc/A-ganeti-fix-root.sh new file mode 100755 index 0000000..e5dc644 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/A-ganeti-fix-root.sh @@ -0,0 +1,11 @@ +#!/bin/sh -x + +. ./0-host.sh +. ./0-ganeti.sh + + +ssh_master mkdir -p /tmp/$host/lib/modules +ssh_master cp -ra /lib/modules/3.2.0-4-amd64 /tmp/$host/lib/modules + +ssh_master chroot /tmp/$host apt-get install --reinstall -y initscripts acpid + diff --git a/recepies/ganeti/migrate-lxc/B-ganeti-network-interfaces.sh b/recepies/ganeti/migrate-lxc/B-ganeti-network-interfaces.sh new file mode 100755 index 0000000..0ba5a3d --- /dev/null +++ b/recepies/ganeti/migrate-lxc/B-ganeti-network-interfaces.sh @@ -0,0 +1,31 @@ +#!/bin/sh -xe + +. ./0-host.sh +. ./0-lxc.sh +. ./0-ganeti.sh + +ssh_lxc cat /var/lib/lxc/$host/config | grep ipv4 | tee $host/ipv4 +public_ip=`grep 193.198 rt/ipv4 | cut -d= -f2 | cut -d/ -f1 | sed 's/ *//'` +local_ip=` grep 10.60 rt/ipv4 | cut -d= -f2 | cut -d/ -f1 | sed 's/ *//'` + +tee /tmp/network-interfaces-$host << __INTERFACES__ +auto eth0 eth1 lo + +iface lo inet loopback + +iface eth0 inet static + address $public_ip + netmask 255.255.254.0 + gateway 193.198.212.1 + +iface eth1 inet static + address $local_ip + netmask 255.255.254.0 +__INTERFACES__ + +# this will backup file on original machine which is still running! +ping -c 1 $host && ssh_master chroot /tmp/$host bak add,commit /etc/network/interfaces + +scp /tmp/network-interfaces-$host root@$master:/tmp/ + +ssh_master mv -v /tmp/network-interfaces-$host /tmp/$host/etc/network/interfaces diff --git a/recepies/ganeti/migrate-lxc/C-ganeti-swap.sh b/recepies/ganeti/migrate-lxc/C-ganeti-swap.sh new file mode 100755 index 0000000..b3783d2 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/C-ganeti-swap.sh @@ -0,0 +1,10 @@ +#!/bin/sh -xe + +. ./0-host.sh +. ./0-ganeti.sh + +ssh_master lvcreate -L 1G -n $host-swap ffzgvg + +ssh_master parted -s /dev/mapper/ffzgvg-$host--swap 'mklabel msdos mkpartfs primary linux-swap 0% 100%' + +ssh_master dmsetup remove ffzgvg-${host}--swapp1 diff --git a/recepies/ganeti/migrate-lxc/D-ganeti-create-instance.sh b/recepies/ganeti/migrate-lxc/D-ganeti-create-instance.sh new file mode 100755 index 0000000..8ee0c3a --- /dev/null +++ b/recepies/ganeti/migrate-lxc/D-ganeti-create-instance.sh @@ -0,0 +1,12 @@ +#!/bin/sh -xe + +. ./0-host.sh +. ./0-lxc.sh +. ./0-ganeti.sh + +ssh_master umount /tmp/$host + +ssh_master dmsetup remove ffzgvg-${host}p1 + +ssh_master gnt-instance add -H kvm:kernel_path=/boot/vmlinuz-3.2-kvmU,initrd_path=/boot/initrd.img-3.2-kvmU -B maxmem=1G,minmem=1G,vcpus=1 -t plain -n vmh12 -o debootstrap+default --disk 0:adopt=$host --disk 1:adopt=$host-swap --no-start $host_fqdn + diff --git a/recepies/ganeti/migrate-lxc/E-ganeti-network-local.sh b/recepies/ganeti/migrate-lxc/E-ganeti-network-local.sh new file mode 100755 index 0000000..60bffc9 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/E-ganeti-network-local.sh @@ -0,0 +1,6 @@ +#!/bin/sh -xe + +. ./0-host.sh +. ./0-ganeti.sh + +ssh_master gnt-instance modify --net add:link=br0060 $host_fqdn diff --git a/recepies/ganeti/migrate-lxc/F-ganeti-drdb.sh b/recepies/ganeti/migrate-lxc/F-ganeti-drdb.sh new file mode 100755 index 0000000..e42bcd5 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/F-ganeti-drdb.sh @@ -0,0 +1,6 @@ +#!/bin/sh -xe + +. ./0-host.sh +. ./0-ganeti.sh + +ssh_master gnt-instance modify -t drbd -n box01 $host_fqdn diff --git a/recepies/ganeti/migrate-lxc/G-ganeti-start.sh b/recepies/ganeti/migrate-lxc/G-ganeti-start.sh new file mode 100755 index 0000000..3d1da5c --- /dev/null +++ b/recepies/ganeti/migrate-lxc/G-ganeti-start.sh @@ -0,0 +1,6 @@ +#!/bin/sh -xe + +. ./0-host.sh +. ./0-ganeti.sh + +ssh_master gnt-instance start $host_fqdn diff --git a/recepies/ganeti/migrate-lxc/H-host-configure.sh b/recepies/ganeti/migrate-lxc/H-host-configure.sh new file mode 100755 index 0000000..4595621 --- /dev/null +++ b/recepies/ganeti/migrate-lxc/H-host-configure.sh @@ -0,0 +1,13 @@ +#!/bin/sh -x + +. ./0-host.sh + +#ssh_host apt-get install --reinstall -y initscripts acpid +ssh_host lsmod | grep button + +ssh_host cat /etc/inittab | tee $host/inittab +grep -v ^# $host/inittab | grep console || echo "1:2345:respawn:/sbin/getty 38400 console" | tee -a $host/inittab && \ + rsync $host/inittab root@$host:/etc/ + +ssh_host bak diff /etc/inittab +ssh_host init q -- 2.20.1