7 start|stop|upgrade|destroy|refresh|prepare|emptycache)
8 echo "Handling command $cmd"
11 echo "Unknown command"
18 centos7|debian8|debian9|debian10)
19 echo "Handling host $host"
27 # TODO: don't modify the side-wide configuration
29 sed -i -e 's/lxc.cap.drop = mac_admin mac_override.*/lxc.cap.drop = mac_admin mac_override/' /usr/share/lxc/config/centos.common.conf
30 # Don't expire root password
31 sed -i -e 's/^ *chroot $rootfs_path passwd -e root/echo # DISABLED # &/' /usr/share/lxc/templates/lxc-centos
37 release=${host#centos}
38 cachedir=/var/cache/lxc/centos/x86_64/$release/rootfs
53 cachedir=/var/cache/lxc/debian/rootfs-$release-amd64
54 export MIRROR=http://ftp.fr.debian.org/debian
57 rootfs=/var/lib/lxc/$host.local/rootfs
60 # Prepare customized template
61 # TODO: only apply generic fixes in the site-wide cache (i.e. nothing FF-specific)
63 if [ ! -e $cachedir ] ; then
64 # Create and destroy an empty container to create the cache
66 lxc-create -t $template -f /etc/lxc/default.conf --name $host.local -- --release $release
72 chroot $cachedir usermod --expiredate $(date +"%Y-%m-%d" -d "1 year") root
73 chroot $cachedir yum install -y avahi-autoipd avahi nscd
74 # Fix nscd restart and stalled avahi pid files
75 rm -rf $cachedir/var/run/
76 ln -sf ../run $cachedir/var/
79 chroot $cachedir apt-get install --yes \
80 avahi-autoipd avahi-daemon unattended-upgrades bash-completion
83 # Fix Avahi compatibility with LXC
84 sed -i -e /^rlimit-nproc=/d $cachedir/etc/avahi/avahi-daemon.conf
94 mount --bind /proc $cachedir/proc
95 chroot $cachedir sh -c "yum update -y"
99 mount --bind /proc $cachedir/proc
100 chroot $cachedir sh -c "apt-get update"
101 LANG=C chroot $cachedir sh -c "unattended-upgrades -d"
102 chroot $cachedir sh -c "apt-get clean"
103 umount $cachedir/proc
105 find $cachedir/var/log/unattended-upgrades -type f -mtime +30 | xargs -r rm
110 # Remove customized template
120 lxc-create -t $template -f /etc/lxc/default.conf --name $host.local -- --release $release
123 echo "$host.local" > $rootfs/etc/hostname
124 # Fix 'hostname -f' == 'localhost'
125 echo "127.0.1.1 $host.local $host" > $rootfs/etc/hosts
128 # Avoid "Invalid Email Address" during CreateForum::testEmailAddressNotAlreadyUsed
129 echo "127.0.1.1 $host.local $host" >> $rootfs/etc/hosts
132 # Grant us SSH access - not in prepare to avoid modifying the site-wide cache
133 # TODO: populate ssh cache if it doesn't exist yet
134 cp /var/cache/lxc/ssh/$host.local/* $rootfs/etc/ssh/
135 chmod 600 $rootfs/etc/ssh/*_key
136 mkdir -p $rootfs/root/.ssh/
137 cp /var/lib/jenkins/.ssh/id_rsa.pub $rootfs/root/.ssh/authorized_keys
142 if [ ! -d $rootfs ] ; then
145 # TODO: write this in VM config (so it can be started manually)?
146 hwaddr=00:16:3e:$(echo $host | md5sum | cut -c -6 | sed s/../\&:/g | sed s/:$//)
147 lxc-start --name $host.local -s lxc.net.0.hwaddr=$hwaddr -s lxc.uts.name=$host --daemon
150 # Harshly^WQuickly stop VM
152 if lxc-ls --active | grep -q $host.local ; then
153 lxc-stop --name $host.local --kill
157 # Harshly^WQuickly destroy VM
159 lxc-destroy -fn $host.local || true