diff --git a/__init__.py b/__init__.py index 02faa81..6ee90f5 100644 --- a/__init__.py +++ b/__init__.py @@ -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)) diff --git a/base.py b/base.py index d2a79f8..f466ffe 100644 --- a/base.py +++ b/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 - - return a dict[][] of for all stopped processes - this information may be used for restarts - """ + """stop service (or all services) of instance """ 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) diff --git a/bin/frappy b/bin/frappy index eed63fd..40480aa 100755 --- a/bin/frappy +++ b/bin/frappy @@ -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:]) diff --git a/bin/nicos b/bin/nicos index aa88f44..1f62c88 100755 --- a/bin/nicos +++ b/bin/nicos @@ -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:]) diff --git a/bin/sea b/bin/sea index afe60d5..8b5d5d0 100755 --- a/bin/sea +++ b/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:]) diff --git a/bin/seweb b/bin/seweb index d1639d6..30ddee7 100755 --- a/bin/seweb +++ b/bin/seweb @@ -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:]) diff --git a/frappyman.py b/frappyman.py index 8433033..5849610 100644 --- a/frappyman.py +++ b/frappyman.py @@ -39,6 +39,13 @@ class FrappyManager(ServiceManager): 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) diff --git a/nicosman.py b/nicosman.py index 4396fc2..9175f00 100644 --- a/nicosman.py +++ b/nicosman.py @@ -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']) diff --git a/seaman.py b/seaman.py index be7233e..c42271f 100644 --- a/seaman.py +++ b/seaman.py @@ -58,7 +58,7 @@ class SeaManager(ServiceManager): sea stop [] sea list [] - is one of main, stick, addons + is one of sea, graph 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)