start frappy server automatically, if not running yet

when restarting NICOS, the frapy servers should be (re-)started
if not running already with the correct config
This commit is contained in:
2022-09-21 17:22:16 +02:00
parent 78edd77ce1
commit 16ba2bcf19
2 changed files with 27 additions and 20 deletions

View File

@ -101,6 +101,7 @@ def frappy_start(**services):
if not secnode: if not secnode:
continue continue
cfginfo = secnode() or '' cfginfo = secnode() or ''
secnode.restart(secnode.read(), False) # restart when needed only
else: else:
if cfginfo: if cfginfo:
new_cfg.append((service, secnode, cfginfo)) new_cfg.append((service, secnode, cfginfo))
@ -151,7 +152,7 @@ def set_se_list():
def frappy(*args, main=None, stick=None, addons=None): def frappy(*args, main=None, stick=None, addons=None):
"""(re)start frappy server(s) with given configs and load setup if needed """(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('<cfg>'): if available, the standard stick is added too - frappy('<cfg>'): if available, the standard stick is added too
- frappy(''): the stick is removed too - frappy(''): the stick is removed too
- addons are not changed when not given - addons are not changed when not given

View File

@ -31,7 +31,7 @@ import os
from os.path import expanduser from os.path import expanduser
from nicos import config, session 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.devices.secop import SecNodeDevice
from nicos.core import Device, anytype, listof from nicos.core import Device, anytype, listof
from nicos.utils.comparestrings import compare from nicos.utils.comparestrings import compare
@ -215,11 +215,17 @@ class FrappyNode(SecNodeDevice, Moveable):
def doStart(self, value): def doStart(self, value):
if value == 'None': if value == 'None':
value = None value = None
self.restart(value) self.restart(value, True) # frappy server will be restarted even when unchanged
def doStop(self): def doStop(self):
"""never busy""" """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): def doRead(self, maxage=0):
if self._cfgvalue is None and self._cache: if self._cfgvalue is None and self._cache:
self._cfgvalue = self._cache.get(self, 'value') self._cfgvalue = self._cache.get(self, 'value')
@ -254,7 +260,7 @@ class FrappyNode(SecNodeDevice, Moveable):
return available_cfg return available_cfg
def disable(self): def disable(self):
seaconn = session.devices.get('seaconn') seaconn = session.devices.get('sea_%s' % self.service)
if seaconn and seaconn._attached_secnode: if seaconn and seaconn._attached_secnode:
seaconn.communicate('frappy_remove %s' % self.service) seaconn.communicate('frappy_remove %s' % self.service)
self._set_status(*self._status) self._set_status(*self._status)
@ -264,23 +270,27 @@ class FrappyNode(SecNodeDevice, Moveable):
code, text = status.DISABLED, 'disabled' code, text = status.DISABLED, 'disabled'
SecNodeDevice._set_status(self, code, text) SecNodeDevice._set_status(self, code, text)
def restart(self, cfg=None): def restart(self, cfg=None, restart=True):
"""restart frappy server """restart frappy server
if value is not given: restart with the same config :param cfg: config for frappy server, if not given, restart with the same config
else restart with given 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:
if cfg is None: # do restart anyway
cfg = self._cfgvalue 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 ins = config.instrument
info = self._service_manager.get_ins_info(ins) 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: if is_cfg:
available_cfg = self.available_cfg(self.service) available_cfg = self.available_cfg(self.service)
failed = False failed = False
@ -297,14 +307,10 @@ class FrappyNode(SecNodeDevice, Moveable):
uri = cfg uri = cfg
if uri != self.uri: if uri != self.uri:
self.uri = '' # disconnect self.uri = '' # disconnect
if was_cfg:
self._service_manager.do_stop(ins, self.service)
if uri: if uri:
if is_cfg: 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 self.uri = uri # connect
else:
self.disable()
self._cfgvalue = cfg self._cfgvalue = cfg
if self._cache: if self._cache:
self._cache.put(self, 'value', cfg) self._cache.put(self, 'value', cfg)