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:
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)
|
||||
|
||||
|
Reference in New Issue
Block a user