Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
scripts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Benjamin Graillot
scripts
Commits
d108b733
Commit
d108b733
authored
Sep 01, 2013
by
Daniel STAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ldap_crans: menage dans les locks morts
parent
d228a7cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
gestion/ldap_crans.py
gestion/ldap_crans.py
+23
-0
No files found.
gestion/ldap_crans.py
View file @
d108b733
...
...
@@ -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'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment