improve service manager
- do not start sea server automatically - replace _SERVICE in FRAPPY_HISTORY by service name - imporve error messages - no fiddling around with sys,path, reply on PYTHONPATH for finding packages
This commit is contained in:
parent
adbe97361f
commit
702db45a76
@ -68,7 +68,7 @@ def run(group, arglist):
|
||||
try:
|
||||
serv.action(action, *arglist)
|
||||
except AttributeError:
|
||||
raise UsageError("do not know '%s'" % ' '.join([serv.group, action] + arglist))
|
||||
raise
|
||||
except UsageError as e:
|
||||
serv.usage()
|
||||
print('ERROR:', str(e))
|
||||
|
23
base.py
23
base.py
@ -207,11 +207,7 @@ class ServiceManager:
|
||||
raise ServiceDown('%s %s is not running' % (service, ins))
|
||||
|
||||
def stop(self, ins, service=None):
|
||||
"""stop service (or all services) of instance <ins>
|
||||
|
||||
return a dict[<ins>][<service>] of <cfg> for all stopped processes
|
||||
this information may be used for restarts
|
||||
"""
|
||||
"""stop service (or all services) of instance <ins>"""
|
||||
procs = self.get_procs()
|
||||
done = False
|
||||
services = self.services if service is None else [service]
|
||||
@ -247,7 +243,7 @@ class ServiceManager:
|
||||
if not self.stop(ins, service):
|
||||
print('nothing to stop')
|
||||
|
||||
def prepare_start(self, ins):
|
||||
def prepare_start(self, ins, service):
|
||||
if ins not in self.env:
|
||||
self.get_info()
|
||||
gr = self.group.upper()
|
||||
@ -273,7 +269,6 @@ class ServiceManager:
|
||||
except ValueError:
|
||||
raise ValueError('do not know %r' % ins)
|
||||
services = list(service_ports) if service is None else [service]
|
||||
# logger.info('start %r %r', services, service_ports)
|
||||
if restart:
|
||||
self.stop(ins, service)
|
||||
else:
|
||||
@ -290,16 +285,15 @@ class ServiceManager:
|
||||
for service_i in services:
|
||||
port = service_ports[service_i]
|
||||
cmd = self.commands[ins] % dict(ins=ins, serv=service_i, port=port, cfg=cfg, pkg=self.pkg)
|
||||
logger.info('COMMAND %s', cmd)
|
||||
if '%(cfg)s' in self.commands[ins] and not cfg:
|
||||
cmd = self.stopped[ins].get(service_i)
|
||||
if not cmd:
|
||||
if restart and service is None:
|
||||
continue # silently ignore missign cfg when restarting all services
|
||||
continue # silently ignore missing cfg when restarting all services
|
||||
raise ValueError('missing cfg for %s %s' % (ins, service_i))
|
||||
wd = os.getcwd()
|
||||
try:
|
||||
start_dir, env = self.prepare_start(ins)
|
||||
start_dir, env = self.prepare_start(ins, service_i)
|
||||
env = dict(os.environ, **env)
|
||||
os.chdir(start_dir)
|
||||
if wait:
|
||||
@ -308,7 +302,7 @@ class ServiceManager:
|
||||
return
|
||||
process = subprocess.Popen(cmd.split(), env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
if not port:
|
||||
logger.info('%s %s started', ins, service_i)
|
||||
logger.info('%sstarted: %s', 're' if restart else '', cmd)
|
||||
continue
|
||||
|
||||
print_wait = True
|
||||
@ -334,14 +328,11 @@ class ServiceManager:
|
||||
except socket.error:
|
||||
time.sleep(0.1 * i)
|
||||
continue
|
||||
if restart:
|
||||
logger.info('%s %s restarted', ins, service_i)
|
||||
else:
|
||||
logger.info('%s %s started', ins, service_i)
|
||||
logger.info('%sstarted: %s', 're' if restart else '', cmd)
|
||||
break
|
||||
else:
|
||||
logger.info(cmd)
|
||||
logger.error('starting %s %s failed', ins, service_i)
|
||||
logger.error('starting failed: %s', cmd)
|
||||
finally:
|
||||
os.chdir(wd)
|
||||
|
||||
|
@ -23,12 +23,6 @@
|
||||
|
||||
import sys
|
||||
from os.path import join, abspath, dirname
|
||||
|
||||
# for packages: servicemanager, frappyhistory
|
||||
sys.path.insert(0, abspath(join(dirname(__file__), '../..')))
|
||||
# for frappy:
|
||||
sys.path.insert(0, abspath(join(dirname(__file__), '../../frappy')))
|
||||
|
||||
from servicemanager import run
|
||||
|
||||
run('frappy', sys.argv[1:])
|
||||
|
@ -23,12 +23,6 @@
|
||||
|
||||
import sys
|
||||
from os.path import join, abspath, dirname
|
||||
|
||||
# for packages: servicemanager, frappyhistory
|
||||
sys.path.insert(0, abspath(join(dirname(__file__), '../..')))
|
||||
# for nicos:
|
||||
sys.path.insert(0, abspath(join(dirname(__file__), '../../nicos')))
|
||||
|
||||
from servicemanager import run
|
||||
|
||||
run('nicos', sys.argv[1:])
|
||||
|
4
bin/sea
4
bin/sea
@ -23,10 +23,6 @@
|
||||
|
||||
import sys
|
||||
from os.path import join, abspath, dirname
|
||||
|
||||
# for packages: servicemanager, frappyhistory
|
||||
sys.path.insert(0, abspath(join(dirname(__file__), '../..')))
|
||||
|
||||
from servicemanager import run
|
||||
|
||||
run('sea', sys.argv[1:])
|
||||
|
@ -23,10 +23,6 @@
|
||||
|
||||
import sys
|
||||
from os.path import join, abspath, dirname
|
||||
|
||||
# for packages: servicemanager, frappyhistory
|
||||
sys.path.insert(0, abspath(join(dirname(__file__), '../..')))
|
||||
|
||||
from servicemanager import run
|
||||
|
||||
run('seweb', sys.argv[1:])
|
||||
|
@ -39,6 +39,13 @@ class FrappyManager(ServiceManager):
|
||||
<instance> is one of %s
|
||||
"""
|
||||
|
||||
def prepare_start(self, ins, service):
|
||||
start_dir, env = super().prepare_start(ins, service)
|
||||
his = env.get('FRAPPY_HISTORY')
|
||||
if his:
|
||||
env['FRAPPY_HISTORY'] = his.replace('_SERVICE', '_' + service)
|
||||
return start_dir, env
|
||||
|
||||
def do_gui(self, ins='', service='main'):
|
||||
try:
|
||||
self.check_running(ins, service)
|
||||
|
@ -36,6 +36,7 @@ ENV_KEYS = {
|
||||
'FRAPPY_STICK_PORT',
|
||||
'FRAPPY_ADDONS_PORT',
|
||||
'SEA_PORT',
|
||||
'PYTHONPATH',
|
||||
}
|
||||
|
||||
|
||||
@ -216,8 +217,8 @@ class NicosManager(ServiceManager):
|
||||
src = join(data, os.readlink(join(data, 'current')))
|
||||
NicosManager.copy_linked(src)
|
||||
|
||||
def prepare_start(self, ins):
|
||||
start_dir, env = super().prepare_start(ins)
|
||||
def prepare_start(self, ins, service):
|
||||
start_dir, env = super().prepare_start(ins, service)
|
||||
instr = '%s.%s' % (env['NICOS_PACKAGE'], ins)
|
||||
env['INSTRUMENT'] = instr
|
||||
start_dir = env.get('NICOS_START', start_dir)
|
||||
@ -225,7 +226,7 @@ class NicosManager(ServiceManager):
|
||||
|
||||
def prepare_client(self, ins):
|
||||
self.check_running(ins, 'daemon')
|
||||
env = self.prepare_start(ins)[1]
|
||||
env = self.prepare_start(ins, 'daemon')[1]
|
||||
os.environ.update(env)
|
||||
os.chdir(join(os.environ['NICOS_ROOT'], env['NICOS_PACKAGE']))
|
||||
sys.path.insert(0, os.environ['NICOS_ROOT'])
|
||||
|
16
seaman.py
16
seaman.py
@ -58,7 +58,7 @@ class SeaManager(ServiceManager):
|
||||
sea stop <instance> [<service>]
|
||||
sea list [<instance>]
|
||||
|
||||
<service> is one of main, stick, addons
|
||||
<service> is one of sea, graph
|
||||
<instance> is one of %s
|
||||
"""
|
||||
|
||||
@ -66,22 +66,20 @@ class SeaManager(ServiceManager):
|
||||
try:
|
||||
self.check_running(ins, 'sea')
|
||||
except ServiceDown as e:
|
||||
print('%s, try to start...' % e)
|
||||
self.do_start(ins)
|
||||
time.sleep(1) # make sure caller did read the message
|
||||
self.usage()
|
||||
print(str(e))
|
||||
except KeyError: # running on an other machine?
|
||||
pass
|
||||
self.usage()
|
||||
run_command('six -sea %s' % ins, wait=True)
|
||||
|
||||
def do_gui(self, ins=''):
|
||||
try:
|
||||
self.check_running(ins, 'sea')
|
||||
except ServiceDown as e:
|
||||
print('%s, try to start...' % e)
|
||||
self.do_start(ins)
|
||||
time.sleep(1) # make sure caller did read the message
|
||||
self.usage()
|
||||
print(str(e))
|
||||
except KeyError: # running on an other machine?
|
||||
pass
|
||||
self.usage()
|
||||
run_command('SeaClient %s' % ins)
|
||||
print('starting sea gui %s' % ins)
|
||||
time.sleep(5)
|
||||
|
Loading…
x
Reference in New Issue
Block a user