diff --git a/commands.py b/commands.py index 4a3b650..d769274 100644 --- a/commands.py +++ b/commands.py @@ -101,6 +101,7 @@ def frappy_start(**services): if not secnode: continue cfginfo = secnode() or '' + secnode.restart(secnode.read(), False) # restart when needed only else: if cfginfo: new_cfg.append((service, secnode, cfginfo)) @@ -151,7 +152,7 @@ def set_se_list(): def frappy(*args, main=None, stick=None, addons=None): """(re)start frappy server(s) with given configs and load setup if needed - - without argument: list running frappy servers + - without argument: list running frappy servers, restart failed frappy servers - frappy(''): if available, the standard stick is added too - frappy(''): the stick is removed too - addons are not changed when not given diff --git a/devices.py b/devices.py index 55c02f5..4120b0a 100644 --- a/devices.py +++ b/devices.py @@ -31,7 +31,7 @@ import os from os.path import expanduser from nicos import config, session -from nicos.core import Override, Param, Moveable, status, DeviceAlias +from nicos.core import Override, Param, Moveable, status, DeviceAlias, SIMULATION, POLLER from nicos.devices.secop import SecNodeDevice from nicos.core import Device, anytype, listof from nicos.utils.comparestrings import compare @@ -215,11 +215,17 @@ class FrappyNode(SecNodeDevice, Moveable): def doStart(self, value): if value == 'None': value = None - self.restart(value) + self.restart(value, True) # frappy server will be restarted even when unchanged def doStop(self): """never busy""" + def doInit(self, mode): + if mode != SIMULATION and session.sessiontype != POLLER: + cfg = self.doRead() + self.restart(cfg, False) # do not restart when not changed + super().doInit(mode) + def doRead(self, maxage=0): if self._cfgvalue is None and self._cache: self._cfgvalue = self._cache.get(self, 'value') @@ -254,7 +260,7 @@ class FrappyNode(SecNodeDevice, Moveable): return available_cfg def disable(self): - seaconn = session.devices.get('seaconn') + seaconn = session.devices.get('sea_%s' % self.service) if seaconn and seaconn._attached_secnode: seaconn.communicate('frappy_remove %s' % self.service) self._set_status(*self._status) @@ -264,23 +270,27 @@ class FrappyNode(SecNodeDevice, Moveable): code, text = status.DISABLED, 'disabled' SecNodeDevice._set_status(self, code, text) - def restart(self, cfg=None): + def restart(self, cfg=None, restart=True): """restart frappy server - if value is not given: restart with the same config - else restart with given config + :param cfg: config for frappy server, if not given, restart with the same config + :param restart: when false, do not restart when already running with same cfg """ - was_cfg = self._cfgvalue and ':' not in self._cfgvalue - if cfg is None: # do restart anyway + if cfg is None: cfg = self._cfgvalue - elif cfg == self._cfgvalue: # probably called from doStart - if cfg == '': - self.disable() - # do not restart in this case - return - is_cfg = cfg and ':' not in cfg ins = config.instrument info = self._service_manager.get_ins_info(ins) + cfginfo = {} + self._service_manager.get_procs(cfginfo=cfginfo) + running_cfg = cfginfo.get((ins, self.service), '') + if cfg == running_cfg: + if not restart: + return + else: + self.disable() + if running_cfg: + self._service_manager.do_stop(ins, self.service) + is_cfg = cfg and ':' not in cfg if is_cfg: available_cfg = self.available_cfg(self.service) failed = False @@ -297,14 +307,10 @@ class FrappyNode(SecNodeDevice, Moveable): uri = cfg if uri != self.uri: self.uri = '' # disconnect - if was_cfg: - self._service_manager.do_stop(ins, self.service) if uri: if is_cfg: - self._service_manager.do_restart(ins, self.service, cfg, self.log) + self._service_manager.do_start(ins, self.service, cfg, logger=self.log) self.uri = uri # connect - else: - self.disable() self._cfgvalue = cfg if self._cache: self._cache.put(self, 'value', cfg)