diff --git a/backup.sh b/backup.sh new file mode 100755 index 0000000..7a693aa --- /dev/null +++ b/backup.sh @@ -0,0 +1,3 @@ +#!/bin/bash + + diff --git a/blockcommit_all.sh b/blockcommit_all.sh new file mode 100755 index 0000000..819fdc8 --- /dev/null +++ b/blockcommit_all.sh @@ -0,0 +1,25 @@ +count=$1 +VMs=$(sudo virsh list --state-running --name | sort -R) + +#sudo aa-teardown +for vm in $VMs +do + echo BLOCKCOMMITTING $vm ... + + retour=$(sudo virsh blockcommit $vm vda --active --verbose --pivot --delete 2>&1 | tee /dev/tty) + if [[ "$retour" =~ 'block copy still active' ]] + then + path_img=$(sudo virsh domblklist $vm | grep vda | cut -d" " -f 8) + sudo virsh blockjob $vm $path_img --pivot --info + sudo virsh blockcommit $vm vda --active --verbose --pivot --delete 2>&1 + fi + + retour=$(sudo virsh blockcommit $vm vdb --active --verbose --pivot --delete 2>&1 | tee /dev/tty) + if [[ "$retour" =~ 'block copy still active' ]] + then + path_img=$(sudo virsh domblklist $vm | grep vdb | cut -d" " -f 8) + sudo virsh blockjob $vm $path_img --pivot --info + sudo virsh blockcommit $vm vda --active --verbose --pivot --delete 2>&1 + fi +done +#sudo systemctl restart apparmor.service diff --git a/execute_cmd_all.sh b/execute_cmd_all.sh new file mode 100755 index 0000000..2226faf --- /dev/null +++ b/execute_cmd_all.sh @@ -0,0 +1,8 @@ +command=$1 +VMs=$(sudo virsh list --state-running --name) + +for vm in $VMs +do + echo Executing on $vm ... + ssh $vm $1 +done diff --git a/execute_script_all.sh b/execute_script_all.sh new file mode 100755 index 0000000..c196742 --- /dev/null +++ b/execute_script_all.sh @@ -0,0 +1,8 @@ +script=$1 +VMs=$(sudo virsh list --state-running --name | grep chalec) + +for vm in $VMs +do + echo Executing script $script on $vm ... + ssh $vm 'bash -s' < $script +done diff --git a/migrate_many_to_aunt.sh b/migrate_many_to_aunt.sh new file mode 100755 index 0000000..e907f27 --- /dev/null +++ b/migrate_many_to_aunt.sh @@ -0,0 +1,15 @@ +count=$1 +VMs=$(sudo virsh list --state-running --name | head -n $count | sort -R) + +for vm in $VMs +do + if [ -z "$(cat /proc/drbd | grep Connected)" ] + then + echo "ERROR : SPLIT BRAIN" + exit 1 + fi + + echo MIGRATING $vm ... + sudo virsh migrate --verbose --live --persistent --undefinesource --abort-on-error $vm qemu+ssh://aunt:223/system + sudo mv /var/backups/vm/mother/$vm /var/backups/vm/aunt +done diff --git a/migrate_many_to_mother.sh b/migrate_many_to_mother.sh new file mode 100755 index 0000000..ab09496 --- /dev/null +++ b/migrate_many_to_mother.sh @@ -0,0 +1,15 @@ +count=$1 +VMs=$(sudo virsh list --state-running --name | head -n $count | sort -R) + +for vm in $VMs +do + if [ -z "$(cat /proc/drbd | grep Connected)" ] + then + echo "ERROR : SPLIT BRAIN" + exit 1 + fi + + echo MIGRATING $vm ... + sudo virsh migrate --verbose --live --persistent --undefinesource --abort-on-error $vm qemu+ssh://mother:222/system + sudo mv /var/backups/vm/aunt/$vm /var/backups/vm/mother +done diff --git a/migrate_to_aunt.sh b/migrate_to_aunt.sh new file mode 100755 index 0000000..1a5b09c --- /dev/null +++ b/migrate_to_aunt.sh @@ -0,0 +1,12 @@ +vm=$1 + +if [ -z "$(cat /proc/drbd | grep Connected)" ] +then + + echo "ERROR : SPLIT BRAIN" + exit 1 +fi + +echo MIGRATING $vm ... +sudo virsh migrate --verbose --live --persistent --undefinesource --abort-on-error $vm qemu+ssh://aunt:223/system +sudo mv /var/backups/vm/mother/$vm /var/backups/vm/aunt diff --git a/migrate_to_mother.sh b/migrate_to_mother.sh new file mode 100755 index 0000000..977d5f5 --- /dev/null +++ b/migrate_to_mother.sh @@ -0,0 +1,12 @@ +vm=$1 + +if [ -z "$(cat /proc/drbd | grep Connected)" ] +then + + echo "ERROR : SPLIT BRAIN" + exit 1 +fi + +echo MIGRATING $vm ... +sudo virsh migrate --verbose --live --persistent --undefinesource --abort-on-error $vm qemu+ssh://mother:222/system +sudo mv /var/backups/vm/aunt/$vm /var/backups/vm/mother diff --git a/migrate_to_mother_p2p.sh b/migrate_to_mother_p2p.sh new file mode 100755 index 0000000..db8d694 --- /dev/null +++ b/migrate_to_mother_p2p.sh @@ -0,0 +1,10 @@ +VMs=$(sudo virsh list --state-running --name) + +for vm in $VMs +do + echo MIGRATING $vm ... + virsh migrate --p2p $vm --live --verbose --undefinesource --persistent \ + --copy-storage-all --abort-on-error qemu+ssh://mother.onlink/system +done + +sudo mv /var/backups/vm/aunt/* /var/backups/vm/mother diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..63bebd1 --- /dev/null +++ b/script.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +#sudo sed -i 's/destemail = cominfra@a-lec.org/destemail = comchalec@a-lec.org/g' /etc/fail2ban/jail.local +#sudo sed -i 's/destemail = root@localhost/destemail = comchalec@a-lec.org/g' /etc/fail2ban/jail.local + +#sudo systemctl restart fail2ban.service + + +#sudo su -c 'echo Defaults mailto="comchalec@a-lec.org" >> /etc/sudoers' + +#sudo sed -i 's/Defaults mailto="cominfra@a-lec.org/ /g' /etc/sudoers + +#sudo etckeeper commit "L'infrastructure envoie ses courriels à comchalec@" + +#sudo apt-get install qemu-guest-agent -y + +#sudo reboot + +#sudo rm /etc/icinga2/conf.d/* + +sudo su -c 'echo -e "[Definition]\nactionstart =\nactionstop =\n" > /etc/fail2ban/action.d/sendmail-common.local' + +sudo etckeeper commit "Désactivation des notifications d'allumage Fail2ban" + +#sudo systemctl restart icinga2 + +sudo systemctl restart fail2ban diff --git a/script_isengard_superv.sh b/script_isengard_superv.sh new file mode 100755 index 0000000..9e7b43c --- /dev/null +++ b/script_isengard_superv.sh @@ -0,0 +1,25 @@ +NAME= +sudo cat << EOF > /etc/icinga2/zones.d/master/$NAME.conf +object Endpoint "NOM_DE_DOMAINE_DE_VM" { +} + +object Zone "NOM_DE_DOMAINE_DE_VM" { +endpoints = [ "NOM_DE_DOMAINE_DE_VM" ] +parent = "master" +} + +object Host "NOM_DE_DOMAINE_DE_VM" { + import "generic-host" + address = "NOM_DE_DOMAINE_DE_VM" + address6 = "NOM_DE_DOMAINE_DE_VM" + vars.os = "GNU/Linux" + vars.client_endpoint = name + + vars.notification["mail"] = { + groups = [ "icingaadmins" ] + } + +} +EOF + +sudo sed -i "s/NOM_DE_DOMAINE_DE_VM/${NAME}/g" /etc/icinga2/zones.d/master/$NAME.conf diff --git a/script_superv.sh b/script_superv.sh new file mode 100755 index 0000000..a0b618d --- /dev/null +++ b/script_superv.sh @@ -0,0 +1,5 @@ +sudo apt-get install icinga2 monitoring-plugins monitoring-plugins-contrib + +sudo sed -i 's/check_mem.pl/check_memory/g' /usr/share/icinga2/include/plugins-contrib.d/operating-system.conf + +sudo systemctl restart icinga2 diff --git a/start_all.sh b/start_all.sh new file mode 100755 index 0000000..4bd6690 --- /dev/null +++ b/start_all.sh @@ -0,0 +1,7 @@ +VMs=$(sudo virsh list --all --name) + +for vm in $VMs +do + echo Starting $vm ... + sudo virsh start $vm +done diff --git a/supervision.sh b/supervision.sh new file mode 100755 index 0000000..5f4f462 --- /dev/null +++ b/supervision.sh @@ -0,0 +1,4 @@ +ssh $1 < script_superv.sh + +sudo sed -i "s/NAME=.*/NAME=$1/g" superv_script_isengard.sh +ssh isengard < superv_script_isengard.sh