servicemanager/__init__.py
Markus Zolliker 3748948b5d better message when server is not running
when a client is started and the server is not running,
issue 'please use ".. start .."' message
2021-04-09 10:15:32 +02:00

80 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
# *****************************************************************************
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Module authors:
# Markus Zolliker <markus.zolliker@psi.ch>
#
# *****************************************************************************
"""start/stop/list of services
this code is currently used:
- from NICOS to start and stop frappy servers
- from a script allowing to start/stop/list (and more) multiple frappy and nicos servers
"""
from servicemanager.base import ServiceManager, ServiceDown, UsageError, get_config
from servicemanager.nicosman import NicosManager
from servicemanager.seaman import SeaManager
from servicemanager.frappyman import FrappyManager
class SewebManager(ServiceManager):
group = 'seweb'
services = ('',)
USAGE = """
Usage:
seaweb list [<instance>]
seaweb start <instance>
seaweb restart <instance>
seaweb stop <instance>
<instance> is one of %s
"""
all = NicosManager, FrappyManager, SeaManager, SewebManager
def run(group, arglist):
try:
parser = get_config()
defaults = parser['DEFAULT']
managers = {cls.group: cls() for cls in all if cls.group + '_command' in defaults}
serv = managers[group]
arglist = arglist + [''] # add dummy argument
if arglist[0].endswith('help'):
serv.usage()
return
action = arglist.pop(0) if hasattr(serv, 'do_' + arglist[0]) else 'gui'
instance = arglist.pop(0) if arglist[0] and arglist[0] not in serv.services else None
if instance is None and serv.main_ins:
instance = serv.main_ins
if instance is not None:
arglist.insert(0, instance)
arglist.pop() # remove dummy argument
try:
serv.action(action, *arglist)
except AttributeError:
raise
except UsageError as e:
serv.usage()
print('ERROR:', str(e))