git://git.onelab.eu
/
nodemanager.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Get defaults from bwlimit. Also remove checks before issuing bwlimit commands. ...
[nodemanager.git]
/
accounts.py
diff --git
a/accounts.py
b/accounts.py
index
12084c2
..
3065408
100644
(file)
--- a/
accounts.py
+++ b/
accounts.py
@@
-23,6
+23,7
@@
maximum stack size.
import Queue
import os
import pwd
import Queue
import os
import pwd
+from grp import getgrnam
import threading
import logger
import threading
import logger
@@
-30,8
+31,9
@@
import tools
# When this variable is true, start after any ensure_created
# When this variable is true, start after any ensure_created
-startingup = False
-# Cumulative delay for starts when startingup is true
+Startingup = False
+# Cumulative delay for starts when Startingup is true
+csd_lock = threading.Lock()
cumstartdelay = 0
# shell path -> account class association
cumstartdelay = 0
# shell path -> account class association
@@
-67,6
+69,7
@@
def get(name):
class Account:
def __init__(self, rec):
class Account:
def __init__(self, rec):
+ logger.verbose('Initing account %s'%rec['name'])
self.name = rec['name']
self.keys = ''
self.initscriptchanged = False
self.name = rec['name']
self.keys = ''
self.initscriptchanged = False
@@
-79,20
+82,23
@@
class Account:
def configure(self, rec):
"""Write <rec['keys']> to my authorized_keys file."""
def configure(self, rec):
"""Write <rec['keys']> to my authorized_keys file."""
+ logger.verbose('in accounts:configure for %s'%self.name)
new_keys = rec['keys']
if new_keys != self.keys:
self.keys = new_keys
dot_ssh = '/home/%s/.ssh' % self.name
new_keys = rec['keys']
if new_keys != self.keys:
self.keys = new_keys
dot_ssh = '/home/%s/.ssh' % self.name
- def do_installation():
- if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
- os.chmod(dot_ssh, 0700)
- tools.write_file(dot_ssh + '/authorized_keys', lambda f: f.write(new_keys))
+ if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
+ os.chmod(dot_ssh, 0700)
+ tools.write_file(dot_ssh + '/authorized_keys', lambda f: f.write(new_keys))
logger.log('%s: installing ssh keys' % self.name)
logger.log('%s: installing ssh keys' % self.name)
- tools.fork_as(self.name, do_installation)
+ user = pwd.getpwnam(self.name)[2]
+ group = getgrnam("slices")[2]
+ os.chown(dot_ssh, user, group)
+ os.chown(dot_ssh + '/authorized_keys', user, group)
def start(self, delay=0): pass
def stop(self): pass
def start(self, delay=0): pass
def stop(self): pass
-
+ def is_running(self): pass
class Worker:
# these semaphores are acquired before creating/destroying an account
class Worker:
# these semaphores are acquired before creating/destroying an account
@@
-110,9
+116,12
@@
class Worker:
def ensure_created(self, rec):
"""Cause the account specified by <rec> to exist if it doesn't already."""
def ensure_created(self, rec):
"""Cause the account specified by <rec> to exist if it doesn't already."""
- self._q.put((self._ensure_created, rec.copy()))
+ if rec.has_key('name'):
+ logger.verbose('Worker.ensure_created with name=%s'%rec['name'])
+ self._q.put((self._ensure_created, rec.copy(), Startingup))
+ logger.verbose('Worker queue has %d item(s)'%self._q.qsize())
- def _ensure_created(self, rec):
+ def _ensure_created(self, rec
, startingup
):
curr_class = self._get_class()
next_class = type_acct_class[rec['type']]
if next_class != curr_class:
curr_class = self._get_class()
next_class = type_acct_class[rec['type']]
if next_class != curr_class:
@@
-122,9
+131,13
@@
class Worker:
finally: self._create_sem.release()
if not isinstance(self._acct, next_class): self._acct = next_class(rec)
else: self._acct.configure(rec)
finally: self._create_sem.release()
if not isinstance(self._acct, next_class): self._acct = next_class(rec)
else: self._acct.configure(rec)
- if startingup:
- self._acct.start(delay=cumstartdelay)
+ if startingup or not self.is_running():
+ csd_lock.acquire()
+ global cumstartdelay
+ delay = cumstartdelay
cumstartdelay += 2
cumstartdelay += 2
+ csd_lock.release()
+ self._acct.start(delay=delay)
elif next_class != curr_class or self._acct.initscriptchanged:
self._acct.start()
elif next_class != curr_class or self._acct.initscriptchanged:
self._acct.start()
@@
-137,6
+150,14
@@
class Worker:
def stop(self): self._q.put((self._stop,))
def _stop(self): self._acct.stop()
def stop(self): self._q.put((self._stop,))
def _stop(self): self._acct.stop()
+ def is_running(self):
+ if self._acct.is_running():
+ status = True
+ else:
+ status = False
+ logger.verbose("Worker(%s): is not running" % self.name)
+ return status
+
def _destroy(self, curr_class):
self._acct = None
if curr_class:
def _destroy(self, curr_class):
self._acct = None
if curr_class:
@@
-153,6
+174,8
@@
class Worker:
"""Repeatedly pull commands off the queue and execute. If memory usage becomes an issue, it might be wise to terminate after a while."""
while True:
try:
"""Repeatedly pull commands off the queue and execute. If memory usage becomes an issue, it might be wise to terminate after a while."""
while True:
try:
+ logger.verbose('Worker:_run : getting - size is %d'%self._q.qsize())
cmd = self._q.get()
cmd[0](*cmd[1:])
cmd = self._q.get()
cmd[0](*cmd[1:])
- except: logger.log_exc()
+ except:
+ logger.log_exc(self.name)