mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
services[name] -> service
This commit is contained in:
parent
42bc8c354a
commit
199258166e
1 changed files with 22 additions and 20 deletions
|
@ -61,27 +61,27 @@ def service_add(name, description=None, log=None, log_type="file", test_status=N
|
||||||
"""
|
"""
|
||||||
services = _get_services()
|
services = _get_services()
|
||||||
|
|
||||||
services[name] = {}
|
services[name] = service = {}
|
||||||
|
|
||||||
if log is not None:
|
if log is not None:
|
||||||
if not isinstance(log, list):
|
if not isinstance(log, list):
|
||||||
log = [log]
|
log = [log]
|
||||||
|
|
||||||
services[name]['log'] = log
|
service['log'] = log
|
||||||
|
|
||||||
if not isinstance(log_type, list):
|
if not isinstance(log_type, list):
|
||||||
log_type = [log_type]
|
log_type = [log_type]
|
||||||
|
|
||||||
if len(log_type) < len(log):
|
if len(log_type) < len(log):
|
||||||
log_type.extend([log_type[-1]] * (len(log) - len(log_type))) # extend list to have the same size as log
|
log_type.extend([log_type[-1]] * (len(log) - len(log_type))) # extend list to have the same size as log
|
||||||
|
|
||||||
if len(log_type) == len(log):
|
if len(log_type) == len(log):
|
||||||
services[name]['log_type'] = log_type
|
service['log_type'] = log_type
|
||||||
else:
|
else:
|
||||||
raise YunohostError('service_add_failed', service=name)
|
raise YunohostError('service_add_failed', service=name)
|
||||||
|
|
||||||
if description:
|
if description:
|
||||||
services[name]['description'] = description
|
service['description'] = description
|
||||||
else:
|
else:
|
||||||
# Try to get the description from systemd service
|
# Try to get the description from systemd service
|
||||||
out = subprocess.check_output("systemctl show %s | grep '^Description='" % name, shell=True).strip()
|
out = subprocess.check_output("systemctl show %s | grep '^Description='" % name, shell=True).strip()
|
||||||
|
@ -92,23 +92,23 @@ def service_add(name, description=None, log=None, log_type="file", test_status=N
|
||||||
if out == name + ".service":
|
if out == name + ".service":
|
||||||
logger.warning("/!\\ Packager ! You added a custom service without specifying a description. Please add a proper Description in the systemd configuration, or use --description to explain what the service does in a similar fashion to existing services.")
|
logger.warning("/!\\ Packager ! You added a custom service without specifying a description. Please add a proper Description in the systemd configuration, or use --description to explain what the service does in a similar fashion to existing services.")
|
||||||
else:
|
else:
|
||||||
services[name]['description'] = out
|
service['description'] = out
|
||||||
|
|
||||||
if need_lock:
|
if need_lock:
|
||||||
services[name]['need_lock'] = True
|
service['need_lock'] = True
|
||||||
|
|
||||||
if test_status:
|
if test_status:
|
||||||
services[name]["test_status"] = test_status
|
service["test_status"] = test_status
|
||||||
|
|
||||||
if test_conf:
|
if test_conf:
|
||||||
services[name]["test_conf"] = test_conf
|
service["test_conf"] = test_conf
|
||||||
|
|
||||||
if needs_exposed_ports:
|
if needs_exposed_ports:
|
||||||
services[name]["needs_exposed_ports"] = needs_exposed_ports
|
service["needs_exposed_ports"] = needs_exposed_ports
|
||||||
|
|
||||||
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_add_failed', service=name)
|
raise YunohostError('service_add_failed', service=name)
|
||||||
|
|
||||||
|
@ -288,6 +288,8 @@ def service_status(names=[]):
|
||||||
if check_names and name not in services.keys():
|
if check_names and name not in services.keys():
|
||||||
raise YunohostError('service_unknown', service=name)
|
raise YunohostError('service_unknown', service=name)
|
||||||
|
|
||||||
|
service = services[name]
|
||||||
|
|
||||||
# this "service" isn't a service actually so we skip it
|
# this "service" isn't a service actually so we skip it
|
||||||
#
|
#
|
||||||
# the historical reason is because regenconf has been hacked into the
|
# the historical reason is because regenconf has been hacked into the
|
||||||
|
@ -296,10 +298,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 services[name].get("status", "") is None:
|
if service.get("status", "") is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
systemd_service = services[name].get("actual_systemd_service", name)
|
systemd_service = service.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:
|
||||||
|
@ -314,8 +316,8 @@ def service_status(names=[]):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
translation_key = "service_description_%s" % name
|
translation_key = "service_description_%s" % name
|
||||||
if "description" in services[name] is not None:
|
if "description" in service is not None:
|
||||||
description = services[name].get("description")
|
description = service.get("description")
|
||||||
else:
|
else:
|
||||||
description = m18n.n(translation_key)
|
description = m18n.n(translation_key)
|
||||||
|
|
||||||
|
@ -336,7 +338,7 @@ def service_status(names=[]):
|
||||||
# Fun stuff™ : to obtain the enabled/disabled status for sysv services,
|
# Fun stuff™ : to obtain the enabled/disabled status for sysv services,
|
||||||
# gotta do this ... cf code of /lib/systemd/systemd-sysv-install
|
# gotta do this ... cf code of /lib/systemd/systemd-sysv-install
|
||||||
if result[name]["start_on_boot"] == "generated":
|
if result[name]["start_on_boot"] == "generated":
|
||||||
result[name]["start_on_boot"] = "enabled" if glob("/etc/rc[S5].d/S??"+name) else "disabled"
|
result[name]["start_on_boot"] = "enabled" if glob("/etc/rc[S5].d/S??" + name) else "disabled"
|
||||||
elif os.path.exists("/etc/systemd/system/multi-user.target.wants/%s.service" % name):
|
elif os.path.exists("/etc/systemd/system/multi-user.target.wants/%s.service" % name):
|
||||||
result[name]["start_on_boot"] = "enabled"
|
result[name]["start_on_boot"] = "enabled"
|
||||||
|
|
||||||
|
@ -344,8 +346,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 services[name]:
|
if "test_status" in service:
|
||||||
p = subprocess.Popen(services[name]["test_status"],
|
p = subprocess.Popen(service["test_status"],
|
||||||
shell=True,
|
shell=True,
|
||||||
executable='/bin/bash',
|
executable='/bin/bash',
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
@ -356,8 +358,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 services[name]:
|
if "test_conf" in service:
|
||||||
p = subprocess.Popen(services[name]["test_conf"],
|
p = subprocess.Popen(service["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