Commit initial: récupération et tri rapide
This commit is contained in:
commit
a52829f96c
104 changed files with 11892 additions and 0 deletions
71
ovh/script_bascule-maitre-vers-esclave.sh
Executable file
71
ovh/script_bascule-maitre-vers-esclave.sh
Executable file
|
@ -0,0 +1,71 @@
|
|||
#!/bin/sh
|
||||
|
||||
SERVEUR_ESCLAVE="srv2"
|
||||
SERVEUR_MAITRE="srv1"
|
||||
RSYNCD_SECRETS="/etc/rsyncd.secrets"
|
||||
RSYNCD_SECRETS_USER="admin"
|
||||
|
||||
# Par défaut, on s'arrête à la première erreur non "catchée"
|
||||
set -ex
|
||||
|
||||
# On vérifie que le script PHP est dans le coin
|
||||
if [ ! -f soapi-ovh-bascule.php ]; then
|
||||
echo "ERREUR: script php de bascule 'soapi-ovh-bascule.php' non présent." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
AVERTISSEMENT :
|
||||
Ce script va désactiver tous les processus de réplication
|
||||
sur le serveur esclave et promouvoir celui-ci comme serveur
|
||||
maître.
|
||||
|
||||
La bascule inverse ou le rétablissement de la situation normale
|
||||
devront être fait à la main.
|
||||
|
||||
Ce script s'arrêtera à la première erreur rencontrée, sans retour
|
||||
en arrière. À vous de déboguer et exécuter les étapes restantes.
|
||||
|
||||
Si possible, commencez par éteindre le serveur Apache du maître :
|
||||
ssh root@$SERVEUR_MAITRE service apache2 stop
|
||||
|
||||
Êtes-vous sûr de vouloir continuer ?
|
||||
EOF
|
||||
|
||||
read TOTO
|
||||
if [ "$( echo "$TOTO" | egrep -ic "^(o|y|oui|yes)$" )" -ne 1 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# On commence par arrêter la synchro des fichiers :
|
||||
# - on arrête le serveur rsync qui recevait les connexions du serveur maître
|
||||
# - au cas où le serveur rsync serait redémarré par erreur, on change le mot de passe desdites connexions.
|
||||
echo "Arrêt du serveur rsyncd sur le serveur esclave..."
|
||||
ssh "root@$SERVEUR_ESCLAVE" service rsync stop
|
||||
echo
|
||||
echo
|
||||
echo "Réinitialisation du mot de passe dans $RSYNCD_SECRETS..."
|
||||
ssh "root@$SERVEUR_ESCLAVE" sed -i.bascule-old "/^$RSYNCD_SECRETS_USER:/d" $RSYNCD_SECRETS
|
||||
echo
|
||||
echo
|
||||
|
||||
# On promeut toutes les instances PostgreSQL
|
||||
# pour ce faire, on charge la bibliothèque de scripts de démarrage
|
||||
# de Debian, histoire de faire un simili "service postgresql promote"
|
||||
echo "Promotion des instances PostgreSQL..."
|
||||
ssh "root@$SERVEUR_ESCLAVE" "if ! type do_ctl_all >/dev/null 2>&1; then . /usr/share/postgresql-common/init.d-functions; fi; do_ctl_all promote 9.1 'Promotion des instances...'"
|
||||
echo
|
||||
echo
|
||||
|
||||
# On démarre Apache
|
||||
echo "Démarrage d'Apache..."
|
||||
ssh "root@$SERVEUR_ESCLAVE" service apache2 start
|
||||
echo
|
||||
echo
|
||||
|
||||
echo "Appel à l'API d'OVH pour rediriger l'IP failover vers le serveur esclave..."
|
||||
php soapi-ovh-bascule.php srv1 srv2 && echo "Bascule demandée, attendre qq dizaines de secondes..."
|
||||
echo
|
||||
echo
|
||||
|
||||
echo "End of script."
|
73
ovh/soapi-ovh-bascule.php
Normal file
73
ovh/soapi-ovh-bascule.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Script de bascule d'une IP failover entre 2 serveurs OVH
|
||||
*
|
||||
* S'appelle ainsi :
|
||||
* php script.php srv-old srv-cible
|
||||
*
|
||||
* Le fichier .auth-api-ovh.ini permet de stocker les identifiants de connexion
|
||||
* et ressemble à :
|
||||
* login = xxNNNNN-ovh
|
||||
* password = xxxxxxxxxxxxxxx
|
||||
*
|
||||
* FIXME: seul hostnameOvh est nécessaire : faire sauter la conf. et passer
|
||||
* les noms des serveurs en argument.
|
||||
*/
|
||||
|
||||
/* Config */
|
||||
$failoverIp = 'ip.fa.il.ov.er';
|
||||
$listeServeurs = array(
|
||||
'srv1' => array(
|
||||
'hostnameOvh' => 'ns111111.ovh.net',
|
||||
'ip' => '1.1.1.1',
|
||||
),
|
||||
'srv2' => array(
|
||||
'hostnameOvh' => 'ns222222.ovh.net',
|
||||
'ip' => '2.2.2.2',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
if ( ! ($identifiants = parse_ini_file('.auth-api-ovh.ini'))) {
|
||||
echo "ERREUR : Impossible de récupérer les identifiants de connexion à l'API OVH.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Vérification des arguments
|
||||
if (empty($argv[1]) or ! in_array($argv[1], array_keys($listeServeurs))) {
|
||||
echo "ERREUR : veuillez spécifier le serveur sur lequel pointe actuellement l'IP failover : " . implode(', ', array_keys($listeServeurs)) . "\n";
|
||||
exit(1);
|
||||
}
|
||||
if (empty($argv[2]) or ! in_array($argv[2], array_keys($listeServeurs))) {
|
||||
echo "ERREUR : veuillez spécifier le serveur vers lequel rediriger l'IP failover : " . implode(', ', array_keys($listeServeurs)) . "\n";
|
||||
exit(1);
|
||||
}
|
||||
$serveurActuel = $argv[1];
|
||||
$serveurDestination = $argv[2];
|
||||
if ($serveurActuel == $serveurDestination) {
|
||||
echo "ERREUR : serveur actuel identique au serveur de destination.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
$soap = new SoapClient("https://www.ovh.com/soapi/soapi-re-1.59.wsdl");
|
||||
|
||||
//login
|
||||
$session = $soap->login($identifiants['login'], $identifiants['password'],"fr", false);
|
||||
|
||||
// Changement de pointage de l'IP failover
|
||||
// doc : http://www.ovh.com/soapi/fr/?method=dedicatedFailoverUpdate
|
||||
$soap->dedicatedFailoverUpdate($session, $listeServeurs[$serveurActuel]['hostnameOvh'], $failoverIp, $listeServeurs[$serveurDestination]['ip']);
|
||||
|
||||
//logout
|
||||
$soap->logout($session);
|
||||
|
||||
} catch(SoapFault $fault) {
|
||||
echo $fault;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Code de retour Ok
|
||||
exit(0);
|
59
ovh/soapi-ovh-listing.php
Normal file
59
ovh/soapi-ovh-listing.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Petit script listant la répartition des IP failover
|
||||
*
|
||||
* Le fichier .auth-api-ovh.ini permet de stocker les identifiants de connexion
|
||||
* et ressemble à :
|
||||
* login = xxNNNNN-ovh
|
||||
* password = xxxxxxxxxxxxxxx
|
||||
*
|
||||
* FIXME: seul hostnameOvh est nécessaire : faire sauter la conf. et passer
|
||||
* les noms des serveurs en argument.
|
||||
*/
|
||||
|
||||
/* Config */
|
||||
$failoverIp = 'ip.fa.il.ov.er';
|
||||
$listeServeurs = array(
|
||||
'srv1' => array(
|
||||
'hostnameOvh' => 'ns111111.ovh.net',
|
||||
'ip' => '1.1.1.1',
|
||||
),
|
||||
'srv2' => array(
|
||||
'hostnameOvh' => 'ns222222.ovh.net',
|
||||
'ip' => '2.2.2.2',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
if ( ! ($identifiants = parse_ini_file('.auth-api-ovh.ini'))) {
|
||||
echo "ERREUR : Impossible de récupérer les identifiants de connexion à l'API OVH.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
$soap = new SoapClient("https://www.ovh.com/soapi/soapi-re-1.59.wsdl");
|
||||
|
||||
//login
|
||||
$session = $soap->login($identifiants['login'], $identifiants['password'],"fr", false);
|
||||
echo "login successfull\n";
|
||||
|
||||
//dedicatedFailoverRipeList
|
||||
foreach ($listeServeurs as $key => $server) {
|
||||
$result = $soap->dedicatedFailoverList($session, $server['hostnameOvh']);
|
||||
echo "$key : ";
|
||||
print_r($result);
|
||||
}
|
||||
|
||||
//logout
|
||||
$soap->logout($session);
|
||||
echo "logout successfull\n";
|
||||
|
||||
} catch(SoapFault $fault) {
|
||||
echo $fault;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Code de retour Ok
|
||||
exit(0);
|
95
ovh/soapi-ovh-renouvellement.php
Normal file
95
ovh/soapi-ovh-renouvellement.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Petit script permettant d'avoir les infos de facturation
|
||||
* sur les services dont le renouvellement est proche.
|
||||
*
|
||||
* Le fichier .auth-api-ovh.ini permet de stocker les identifiants de connexion
|
||||
* et ressemble à :
|
||||
* login = xxNNNNN-ovh
|
||||
* password = xxxxxxxxxxxxxxx
|
||||
*/
|
||||
define('STATE_OK', 0);
|
||||
define('STATE_WARNING', 1);
|
||||
define('STATE_CRITICAL', 2);
|
||||
define('STATE_UNKNOWN', 3);
|
||||
define('STATE_DEPENDENT', 4);
|
||||
|
||||
|
||||
// Reading commande line options
|
||||
$options = getopt('w:c:h');
|
||||
if (in_array('h', $options)) {
|
||||
echo <<<EOT
|
||||
-w warning_level
|
||||
-c critical_level
|
||||
EOT;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$compil = array(
|
||||
STATE_WARNING => array('arg' => 'w', 'intitule' => 'warning'),
|
||||
STATE_CRITICAL => array('arg' => 'c', 'intitule' => 'critical'),
|
||||
);
|
||||
$finalMsg = array(
|
||||
STATE_OK => 'OK',
|
||||
STATE_WARNING => 'WARNING:',
|
||||
STATE_CRITICAL => 'CRITICAL:',
|
||||
);
|
||||
$finalState = STATE_OK;
|
||||
|
||||
// Checking values in command line arguments
|
||||
foreach ($compil as $item) {
|
||||
if ( ! isset($options[$item['arg']])) {
|
||||
printf("ERROR: Missing argument '%s' (%s).\n", $item['arg'], $item['intitule']);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
$options[$item['arg']] = (int) $options[$item['arg']];
|
||||
if ($options[$item['arg']] <= 0) {
|
||||
printf("ERROR: Unacceptable value for '%s' (%s).\n", $item['arg'], $item['intitule']);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
}
|
||||
if ($options['c'] > $options['w']) {
|
||||
echo "ERROR: warning level lower than critical level.\n";
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
// Lecture des informations de connexion
|
||||
if ( ! ($identifiants = parse_ini_file('.auth-api-ovh.ini'))) {
|
||||
echo "ERREUR: Impossible de récupérer les identifiants de connexion à l'API OVH.\n";
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
try {
|
||||
$soap = new SoapClient("https://www.ovh.com/soapi/soapi-re-1.59.wsdl");
|
||||
|
||||
//login
|
||||
$session = $soap->login($identifiants['login'], $identifiants['password'],"fr", false);
|
||||
|
||||
// checks...
|
||||
$listingExpirations = $soap->billingGetReferencesToExpired($session, $options['w']);
|
||||
// We try to avoid making a second call to the OVH API
|
||||
// (no wasting of resources :)
|
||||
// so we check, for each element, if the expiration delay is below the
|
||||
// critical level
|
||||
foreach ($listingExpirations as $item) {
|
||||
if (strtotime($item->expired) < (time() + 86400 * $options['c'])) {
|
||||
$finalMsg[STATE_CRITICAL] .= ' [' . $item->name . '(' . $item->type . ') will expire at ' . $item->expired . ']';
|
||||
$finalState = STATE_CRITICAL;
|
||||
} else {
|
||||
$finalMsg[STATE_WARNING] .= ' [' . $item->name . '(' . $item->type . ') will expire at ' . $item->expired . ']';
|
||||
if ($finalState == STATE_OK)
|
||||
$finalState = STATE_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
//logout
|
||||
$soap->logout($session);
|
||||
} catch(SoapFault $fault) {
|
||||
echo "ERREUR: soapi: " . $fault;
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
// Code de retour Ok
|
||||
echo $finalMsg[$finalState] . "\n";
|
||||
exit($finalState);
|
Loading…
Add table
Add a link
Reference in a new issue