On attend plus le lock : on rale et on quitte.
darcs-hash:20040915210652-41617-1e2ab9b10f7fa5773d84c7ac52958c0398e86236.gz
This commit is contained in:
parent
7c697abdcf
commit
cd174ee0d8
2 changed files with 32 additions and 3 deletions
|
@ -19,7 +19,7 @@ if os.getuid() != 0:
|
||||||
signal.signal(signal.SIGINT,signal.SIG_IGN) # Pas de Ctrl-C
|
signal.signal(signal.SIGINT,signal.SIG_IGN) # Pas de Ctrl-C
|
||||||
|
|
||||||
db = crans_ldap()
|
db = crans_ldap()
|
||||||
make_lock('auto_generate')
|
make_lock('auto_generate',0)
|
||||||
|
|
||||||
##### Options fournies ?
|
##### Options fournies ?
|
||||||
try :
|
try :
|
||||||
|
|
|
@ -8,9 +8,12 @@ Licence : GPLv2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os,string,time,sys, affich_tools
|
import os,string,time,sys, affich_tools
|
||||||
|
from commands import getoutput
|
||||||
|
|
||||||
def make_lock(lock_name, lock_comment='') :
|
def make_lock(lock_name, lock_comment='',nowait=1) :
|
||||||
""" Création d'un lock """
|
""" Création d'un lock
|
||||||
|
si nowait=0 fait un sys.exit(254) quand un ancien lock actif est rencontré
|
||||||
|
"""
|
||||||
lock_file = '/var/lock/' + lock_name
|
lock_file = '/var/lock/' + lock_name
|
||||||
if os.path.isfile(lock_file) :
|
if os.path.isfile(lock_file) :
|
||||||
### Lock existant
|
### Lock existant
|
||||||
|
@ -24,6 +27,32 @@ def make_lock(lock_name, lock_comment='') :
|
||||||
if os.system( "ps %s > /dev/null 2>&1" % pid ) :
|
if os.system( "ps %s > /dev/null 2>&1" % pid ) :
|
||||||
# Le script lockant ne tourne plus
|
# Le script lockant ne tourne plus
|
||||||
os.remove(lock_file)
|
os.remove(lock_file)
|
||||||
|
elif nowait :
|
||||||
|
sys.stderr.write('Lock : %s\n' % lock_file)
|
||||||
|
l=getoutput('ps -o user,pid,etime --no-headers %s' % pid)
|
||||||
|
data = l.split()
|
||||||
|
|
||||||
|
# Formatate de etime
|
||||||
|
s = data[-1].split('-')
|
||||||
|
if len(s)==2 :
|
||||||
|
txt = '%s jour(s) ' % s[0]
|
||||||
|
s=s[1]
|
||||||
|
else :
|
||||||
|
txt = ''
|
||||||
|
s=s[0]
|
||||||
|
|
||||||
|
s = s.split(':')
|
||||||
|
if len(s) == 3 :
|
||||||
|
txt = '%sh%smin%ss' % tuple(s)
|
||||||
|
elif len(s) == 2 :
|
||||||
|
txt = '%smin%ss' % tuple(s)
|
||||||
|
else :
|
||||||
|
txt = '???'
|
||||||
|
|
||||||
|
data[-1]=txt
|
||||||
|
|
||||||
|
sys.stderr.write('\tpropriétaire : %s\n\tpid : %s\n\tdémarré depuis %s\n' % tuple(data) )
|
||||||
|
sys.exit(254)
|
||||||
else :
|
else :
|
||||||
# Il faut attendre
|
# Il faut attendre
|
||||||
a = affich_tools.anim('\tattente du lock')
|
a = affich_tools.anim('\tattente du lock')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue