Managing SSH chroots to backup a lot of machines
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.6 KiB

  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # Load ~/.VagrantFile if exist, permit local config provider
  4. vagrantfile = File.join("#{Dir.home}", '.VagrantFile')
  5. load File.expand_path(vagrantfile) if File.exists?(vagrantfile)
  6. Vagrant.configure('2') do |config|
  7. config.vm.synced_folder "./", "/vagrant", type: "rsync", rsync__exclude: [ '.vagrant', '.git', 'build' ]
  8. config.ssh.shell="/bin/sh"
  9. config.vm.provider :libvirt do |libvirt|
  10. libvirt.storage :file, :size => '10G', :device => 'vdb'
  11. end
  12. $install = <<SCRIPT
  13. ln -fs /vagrant/bkctld /usr/sbin/bkctld
  14. ln -fs /vagrant/lib /usr/lib/bkctld
  15. ln -fs /vagrant/tpl /usr/share/bkctld
  16. ln -fs /vagrant/bash_completion /usr/share/bash-completion/completions/bkctld
  17. ln -fs /vagrant/bkctld.conf /etc/default/bkctld
  18. ln -fs /vagrant/bkctld.service /etc/systemd/system/bkctld.service && systemctl daemon-reload
  19. mkdir -p /usr/lib/nagios/plugins/
  20. SCRIPT
  21. $deps = <<SCRIPT
  22. DEBIAN_FRONTEND=noninteractive apt-get -yq install openssh-server btrfs-tools rsync lsb-base coreutils sed dash mount openssh-sftp-server libc6 bash-completion duc-nox cryptsetup bats
  23. SCRIPT
  24. $pre_part = <<SCRIPT
  25. sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
  26. sed -i -e 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen && \
  27. echo 'LANG="fr_FR.UTF-8"'>/etc/default/locale && \
  28. dpkg-reconfigure --frontend=noninteractive locales && \
  29. update-locale LANG=fr_FR.UTF-8
  30. lsof | awk '/backup/ { print $2 }' | xargs --no-run-if-empty kill -9
  31. grep -q /backup /proc/mounts && umount -R /backup
  32. exit 0
  33. SCRIPT
  34. $post_part = <<SCRIPT
  35. mkdir -p /backup
  36. mount /dev/vdb /backup
  37. SCRIPT
  38. nodes = [
  39. { :version => "stretch", :fs => "btrfs" },
  40. { :version => "stretch", :fs => "ext4" },
  41. { :version => "buster", :fs => "btrfs" },
  42. { :version => "buster", :fs => "ext4" }
  43. ]
  44. nodes.each do |i|
  45. config.vm.define "#{i[:version]}-#{i[:fs]}" do |node|
  46. node.vm.hostname = "bkctld-#{i[:version]}-#{i[:fs]}"
  47. node.vm.box = "debian/#{i[:version]}64"
  48. config.vm.provision "deps", type: "shell", :inline => $deps
  49. config.vm.provision "install", type: "shell", :inline => $install
  50. config.vm.provision "pre_part", type: "shell", :inline => $pre_part
  51. config.vm.provision "part", type: "shell", :inline => "mkfs.btrfs -f /dev/vdb" if "#{i[:fs]}" == "btrfs"
  52. config.vm.provision "part", type: "shell", :inline => "mkfs.ext4 -q -F /dev/vdb" if "#{i[:fs]}" == "ext4"
  53. config.vm.provision "post_part", type: "shell", :inline => $post_part
  54. config.vm.provision "test", type: "shell", :inline => "bats /vagrant/test/*.bats"
  55. end
  56. end
  57. end