mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
service -> infos ... + misc small syntax improvements
This commit is contained in:
parent
199258166e
commit
95dd1e2707
1 changed files with 28 additions and 25 deletions
|
@ -125,14 +125,13 @@ def service_remove(name):
|
||||||
"""
|
"""
|
||||||
services = _get_services()
|
services = _get_services()
|
||||||
|
|
||||||
try:
|
if name not in services:
|
||||||
del services[name]
|
|
||||||
except KeyError:
|
|
||||||
raise YunohostError('service_unknown', service=name)
|
raise YunohostError('service_unknown', service=name)
|
||||||
|
|
||||||
|
del services[name]
|
||||||
try:
|
try:
|
||||||
_save_services(services)
|
_save_services(services)
|
||||||
except:
|
except Exception:
|
||||||
# we'll get a logger.warning with more details in _save_services
|
# we'll get a logger.warning with more details in _save_services
|
||||||
raise YunohostError('service_remove_failed', service=name)
|
raise YunohostError('service_remove_failed', service=name)
|
||||||
|
|
||||||
|
@ -275,20 +274,24 @@ def service_status(names=[]):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
services = _get_services()
|
services = _get_services()
|
||||||
check_names = True
|
|
||||||
result = {}
|
|
||||||
|
|
||||||
|
# If function was called with a specific list of service
|
||||||
|
if names != []:
|
||||||
|
# If user wanna check the status of a single service
|
||||||
if isinstance(names, str):
|
if isinstance(names, str):
|
||||||
names = [names]
|
names = [names]
|
||||||
elif len(names) == 0:
|
|
||||||
names = services.keys()
|
|
||||||
check_names = False
|
|
||||||
|
|
||||||
|
# Validate service names requested
|
||||||
for name in names:
|
for name in names:
|
||||||
if check_names and name not in services.keys():
|
if name not in services.keys():
|
||||||
raise YunohostError('service_unknown', service=name)
|
raise YunohostError('service_unknown', service=name)
|
||||||
|
|
||||||
service = services[name]
|
# Filter only requested servivces
|
||||||
|
services = {k: v for k, v in services.items() if k in names}
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
for name, infos in services.items():
|
||||||
|
|
||||||
# this "service" isn't a service actually so we skip it
|
# this "service" isn't a service actually so we skip it
|
||||||
#
|
#
|
||||||
|
@ -298,10 +301,10 @@ def service_status(names=[]):
|
||||||
# the hack was to add fake services...
|
# the hack was to add fake services...
|
||||||
# we need to extract regenconf from service at some point, also because
|
# we need to extract regenconf from service at some point, also because
|
||||||
# some app would really like to use it
|
# some app would really like to use it
|
||||||
if service.get("status", "") is None:
|
if infos.get("status", "") is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
systemd_service = service.get("actual_systemd_service", name)
|
systemd_service = infos.get("actual_systemd_service", name)
|
||||||
status = _get_service_information_from_systemd(systemd_service)
|
status = _get_service_information_from_systemd(systemd_service)
|
||||||
|
|
||||||
if status is None:
|
if status is None:
|
||||||
|
@ -316,8 +319,8 @@ def service_status(names=[]):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
translation_key = "service_description_%s" % name
|
translation_key = "service_description_%s" % name
|
||||||
if "description" in service is not None:
|
if "description" in infos is not None:
|
||||||
description = service.get("description")
|
description = infos.get("description")
|
||||||
else:
|
else:
|
||||||
description = m18n.n(translation_key)
|
description = m18n.n(translation_key)
|
||||||
|
|
||||||
|
@ -346,8 +349,8 @@ def service_status(names=[]):
|
||||||
result[name]['last_state_change'] = datetime.utcfromtimestamp(status["StateChangeTimestamp"] / 1000000)
|
result[name]['last_state_change'] = datetime.utcfromtimestamp(status["StateChangeTimestamp"] / 1000000)
|
||||||
|
|
||||||
# 'test_status' is an optional field to test the status of the service using a custom command
|
# 'test_status' is an optional field to test the status of the service using a custom command
|
||||||
if "test_status" in service:
|
if "test_status" in infos:
|
||||||
p = subprocess.Popen(service["test_status"],
|
p = subprocess.Popen(infos["test_status"],
|
||||||
shell=True,
|
shell=True,
|
||||||
executable='/bin/bash',
|
executable='/bin/bash',
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
@ -358,8 +361,8 @@ def service_status(names=[]):
|
||||||
result[name]["status"] = "running" if p.returncode == 0 else "failed"
|
result[name]["status"] = "running" if p.returncode == 0 else "failed"
|
||||||
|
|
||||||
# 'test_status' is an optional field to test the status of the service using a custom command
|
# 'test_status' is an optional field to test the status of the service using a custom command
|
||||||
if "test_conf" in service:
|
if "test_conf" in infos:
|
||||||
p = subprocess.Popen(service["test_conf"],
|
p = subprocess.Popen(infos["test_conf"],
|
||||||
shell=True,
|
shell=True,
|
||||||
executable='/bin/bash',
|
executable='/bin/bash',
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
|
Loading…
Add table
Reference in a new issue