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