Detabification massive.
darcs-hash:20051018083823-d1718-09c2df38cfb707d3c3679188b9b9a812009f4f7c.gz
This commit is contained in:
parent
3c54fb2904
commit
37b21339a6
40 changed files with 1473 additions and 1473 deletions
|
@ -1,14 +1,14 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
# $Id: secours.py,v 1.2 2005-08-27 11:56:50 pauget Exp $
|
||||
# $Id: secours.py,v 1.3 2005-10-18 08:38:22 bernat Exp $
|
||||
|
||||
""" Script de reconfigure des services en connexion de secours
|
||||
Arguments :
|
||||
test : teste la connexion et passe en secours si besoin
|
||||
normal : force la connexion normale
|
||||
secours : force la connexion de secours
|
||||
auto : permet la modification automatique de l'état
|
||||
test : teste la connexion et passe en secours si besoin
|
||||
normal : force la connexion normale
|
||||
secours : force la connexion de secours
|
||||
auto : permet la modification automatique de l'état
|
||||
Sans argument configure les services comme indiqué dans etat_maitre
|
||||
|
||||
Frédéric Pauget août 2005
|
||||
|
@ -27,7 +27,7 @@ if hostname == 'rouge' :
|
|||
cmds = [ '/etc/init.d/postfix restart' , '/etc/init.d/bind9 reload' ]
|
||||
elif hostname == 'sila' :
|
||||
fichiers = { '/etc/bind/named.conf.options' : '//' ,
|
||||
'/etc/squid/squid.conf' : '#' }
|
||||
'/etc/squid/squid.conf' : '#' }
|
||||
cmds = [ '/etc/init.d/squid reload' , '/etc/init.d/bind9 reload' ]
|
||||
elif hostname == 'bleu' :
|
||||
fichiers = { '/etc/postfix/main.cf' : '#' }
|
||||
|
@ -70,34 +70,34 @@ def edit(file,comment,etat) :
|
|||
new = ''
|
||||
reste = 0 # Nombre de lignes restant à traiter
|
||||
while line :
|
||||
l = line.rstrip()
|
||||
l = line.rstrip()
|
||||
mo = sre.match('^(.*)'+signal+'(|-.)$',l)
|
||||
if (mo and len(mo.group(1)) > 1) or reste:
|
||||
# Ligne pour secours
|
||||
if not sre.match('^' + comment,l) and etat == 'normal':
|
||||
# On est actuellement configuré en secours
|
||||
# Il faut passer en normal
|
||||
new += comment + line
|
||||
elif sre.match('^' + comment,l) and etat == 'secours' :
|
||||
# On est actuellement configuré en normal
|
||||
# Il faut passer en secours
|
||||
new += line.replace(comment,'',1)
|
||||
else :
|
||||
# Rien à faire, on est bien configuré
|
||||
new += line
|
||||
# Ligne pour secours
|
||||
if not sre.match('^' + comment,l) and etat == 'normal':
|
||||
# On est actuellement configuré en secours
|
||||
# Il faut passer en normal
|
||||
new += comment + line
|
||||
elif sre.match('^' + comment,l) and etat == 'secours' :
|
||||
# On est actuellement configuré en normal
|
||||
# Il faut passer en secours
|
||||
new += line.replace(comment,'',1)
|
||||
else :
|
||||
# Rien à faire, on est bien configuré
|
||||
new += line
|
||||
if reste :
|
||||
reste -= 1
|
||||
elif mo and len(mo.group(1)) == 0:
|
||||
# On a une ligne avec secours uniquement, c'est les n
|
||||
# prochaines lignes qui font foi
|
||||
try : reste = int(mo.group(2)[1:])
|
||||
except : reste = 1
|
||||
# prochaines lignes qui font foi
|
||||
try : reste = int(mo.group(2)[1:])
|
||||
except : reste = 1
|
||||
new += line
|
||||
else :
|
||||
# Ligne normale
|
||||
new += line
|
||||
else :
|
||||
# Ligne normale
|
||||
new += line
|
||||
|
||||
line = fd.readline()
|
||||
line = fd.readline()
|
||||
|
||||
fd.close()
|
||||
|
||||
|
@ -109,45 +109,45 @@ if __name__ == '__main__' :
|
|||
etat_maitre, mode = map(str.strip,open(path+'/etat_maitre').readlines())
|
||||
nouvel_etat = etat_maitre
|
||||
try:
|
||||
etat_actuel = open('%s/etat_%s' % (path,hostname)).readline().strip()
|
||||
etat_actuel = open('%s/etat_%s' % (path,hostname)).readline().strip()
|
||||
except :
|
||||
etat_actuel = None
|
||||
|
||||
etat_actuel = None
|
||||
|
||||
if len(sys.argv) == 2 :
|
||||
if sys.argv[1] == 'secours' :
|
||||
print "Connexion de secours forcée."
|
||||
nouvel_etat = 'secours'
|
||||
nouvel_etat = 'secours'
|
||||
mode = 'manuel'
|
||||
open(path+'/etat_maitre','w').write('%s\n%s'% (nouvel_etat,mode))
|
||||
open(path+'/etat_maitre','w').write('%s\n%s'% (nouvel_etat,mode))
|
||||
|
||||
elif sys.argv[1] == 'normal' :
|
||||
print "Connexion normale forcée."
|
||||
nouvel_etat = 'normal'
|
||||
nouvel_etat = 'normal'
|
||||
mode = 'manuel'
|
||||
open(path+'/etat_maitre','w').write('%s\n%s'% (nouvel_etat,mode))
|
||||
|
||||
elif sys.argv[1] in ( 'auto', 'test' ) :
|
||||
open(path+'/etat_maitre','w').write('%s\n%s'% (nouvel_etat,mode))
|
||||
|
||||
elif sys.argv[1] in ( 'auto', 'test' ) :
|
||||
if sys.argv[1] == 'auto' :
|
||||
mode = 'auto'
|
||||
|
||||
if mode != 'auto' :
|
||||
print 'Mode manuel, passer en mode auto pour tester'
|
||||
sys.exit(1)
|
||||
|
||||
# On choisi le mode de connexion
|
||||
if normal_ok() : nouvel_etat = 'normal'
|
||||
else : nouvel_etat = 'secours'
|
||||
|
||||
if nouvel_etat != etat_maitre or sys.argv[1] == 'auto' :
|
||||
open(path + '/etat_maitre','w').write('%s\n%s'% (nouvel_etat,mode))
|
||||
|
||||
mode = 'auto'
|
||||
|
||||
if mode != 'auto' :
|
||||
print 'Mode manuel, passer en mode auto pour tester'
|
||||
sys.exit(1)
|
||||
|
||||
# On choisi le mode de connexion
|
||||
if normal_ok() : nouvel_etat = 'normal'
|
||||
else : nouvel_etat = 'secours'
|
||||
|
||||
if nouvel_etat != etat_maitre or sys.argv[1] == 'auto' :
|
||||
open(path + '/etat_maitre','w').write('%s\n%s'% (nouvel_etat,mode))
|
||||
|
||||
print "Mode %s" % mode
|
||||
|
||||
|
||||
if nouvel_etat == etat_actuel :
|
||||
print etat_actuel
|
||||
print etat_actuel
|
||||
else :
|
||||
# Il faut changer
|
||||
sys.stderr.write("Passage en mode %s\n" % nouvel_etat) # Ecriture sur stderr pour le cron
|
||||
sys.stderr.write("Passage en mode %s\n" % nouvel_etat) # Ecriture sur stderr pour le cron
|
||||
for f, c in fichiers.items() :
|
||||
try:
|
||||
print 'Edition de %s' % f
|
||||
|
@ -155,7 +155,7 @@ if __name__ == '__main__' :
|
|||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
open('%s/etat_%s' % (path,hostname),'w').write(nouvel_etat)
|
||||
open('%s/etat_%s' % (path,hostname),'w').write(nouvel_etat)
|
||||
for c in cmds :
|
||||
os.system(c)
|
||||
os.system(c)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue