Commit initial des scripts d'admin

This commit is contained in:
Adrien Bourmault 2022-05-20 22:13:38 +02:00 committed by admin666
parent 4588891f56
commit 74925a1ae7
14 changed files with 176 additions and 0 deletions

3
backup.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash

25
blockcommit_all.sh Executable file
View File

@ -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

8
execute_cmd_all.sh Executable file
View File

@ -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

8
execute_script_all.sh Executable file
View File

@ -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

15
migrate_many_to_aunt.sh Executable file
View File

@ -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

15
migrate_many_to_mother.sh Executable file
View File

@ -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

12
migrate_to_aunt.sh Executable file
View File

@ -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

12
migrate_to_mother.sh Executable file
View File

@ -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

10
migrate_to_mother_p2p.sh Executable file
View File

@ -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

27
script.sh Executable file
View File

@ -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

25
script_isengard_superv.sh Executable file
View File

@ -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

5
script_superv.sh Executable file
View File

@ -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

7
start_all.sh Executable file
View File

@ -0,0 +1,7 @@
VMs=$(sudo virsh list --all --name)
for vm in $VMs
do
echo Starting $vm ...
sudo virsh start $vm
done

4
supervision.sh Executable file
View File

@ -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