Commit d108b733 authored by Daniel STAN's avatar Daniel STAN

ldap_crans: menage dans les locks morts

parent d228a7cb
......@@ -11,6 +11,7 @@ Licence : GPLv2
from socket import gethostname
import smtplib, re, os, random, string, time, sys, pwd
import errno
import ldap, ldap.modlist, ldap_passwd
import netaddr
......@@ -4007,6 +4008,19 @@ def crans_ldap(readonly=False):
db = CransLdap()
return db
def pid_exists(pid):
"""Check whether pid exists in the current process table.
Credits:
http://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid
"""
if pid < 0:
return False
try:
os.kill(pid, 0)
except OSError, e:
return e.errno == errno.EPERM
else:
return True
if __name__ == '__main__':
import sys
......@@ -4014,6 +4028,7 @@ if __name__ == '__main__':
usage = u"""Usage %s [ACTION]
--lock : donne la liste des locks actifs
--purgelock : supprime tous les locks de la base LDAP
--zombielock : supprime les locks de processus plantés sur ce serveur
--menage : supprime les machines des anciens adhérents""" % sys.argv[0]
if len(sys.argv) != 2:
......@@ -4029,6 +4044,14 @@ if __name__ == '__main__':
cprint(u"Suppression de tous les locks")
crans_ldap().remove_lock('*')
elif '--zombielock' in sys.argv:
cprint(u"Suppression des locks zombies")
for (dn, attrs) in crans_ldap().list_locks():
[lockhost, pid] = attrs['lockid'][0].split('-')[0:2]
if hostname == lockhost and not pid_exists(int(pid)):
cprint(u"Suppresion de %s" % repr(attrs))
crans_ldap().remove_lock(dn)
elif '--menage' in sys.argv:
cprint(u"Ménage des machines des adhérents partis...")
machines = crans_ldap().search('paiement!=%s&host=*.crans.org' % ann_scol , 'w')['machine']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment