mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
add the systemd logs
This commit is contained in:
parent
dffecf4ae6
commit
836ec050fb
1 changed files with 37 additions and 19 deletions
|
@ -49,7 +49,7 @@ MOULINETTE_LOCK = "/var/run/moulinette_yunohost.lock"
|
||||||
logger = log.getActionLogger('yunohost.service')
|
logger = log.getActionLogger('yunohost.service')
|
||||||
|
|
||||||
|
|
||||||
def service_add(name, status=None, log=None, runlevel=None, need_lock=False, description=None):
|
def service_add(name, status=None, log=None, runlevel=None, need_lock=False, description=None, type_log="file"):
|
||||||
"""
|
"""
|
||||||
Add a custom service
|
Add a custom service
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ def service_add(name, status=None, log=None, runlevel=None, need_lock=False, des
|
||||||
runlevel -- Runlevel priority of the service
|
runlevel -- Runlevel priority of the service
|
||||||
need_lock -- Use this option to prevent deadlocks if the service does invoke yunohost commands.
|
need_lock -- Use this option to prevent deadlocks if the service does invoke yunohost commands.
|
||||||
description -- description of the service
|
description -- description of the service
|
||||||
|
type_log -- Precise if the corresponding log is a file or a systemd log
|
||||||
"""
|
"""
|
||||||
services = _get_services()
|
services = _get_services()
|
||||||
|
|
||||||
|
@ -69,8 +70,23 @@ def service_add(name, status=None, log=None, runlevel=None, need_lock=False, des
|
||||||
services[name] = {'status': status}
|
services[name] = {'status': status}
|
||||||
|
|
||||||
if log is not None:
|
if log is not None:
|
||||||
|
if not isinstance(log, list):
|
||||||
|
log = [log]
|
||||||
|
|
||||||
services[name]['log'] = log
|
services[name]['log'] = log
|
||||||
|
|
||||||
|
if not isinstance(type_log, list):
|
||||||
|
type_log = [type_log]
|
||||||
|
|
||||||
|
if len(type_log) < len(log):
|
||||||
|
type_log.extend([type_log[-1]] * (len(log) - len(type_log))) # extend list to have the same size as log
|
||||||
|
|
||||||
|
if len(type_log) == len(log):
|
||||||
|
services[name]['type_log'] = type_log
|
||||||
|
else:
|
||||||
|
raise YunohostError('service_add_failed', service=name)
|
||||||
|
|
||||||
|
|
||||||
if runlevel is not None:
|
if runlevel is not None:
|
||||||
services[name]['runlevel'] = runlevel
|
services[name]['runlevel'] = runlevel
|
||||||
|
|
||||||
|
@ -367,18 +383,17 @@ def service_log(name, number=50):
|
||||||
raise YunohostError('service_no_log', service=name)
|
raise YunohostError('service_no_log', service=name)
|
||||||
|
|
||||||
log_list = services[name]['log']
|
log_list = services[name]['log']
|
||||||
|
type_log_list = services[name]['type_log']
|
||||||
if not isinstance(log_list, list):
|
|
||||||
log_list = [log_list]
|
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
for log_path in log_list:
|
for index in range(len(log_list)):
|
||||||
|
log_path = log_list[index]
|
||||||
|
log_type = type_log_list[index]
|
||||||
|
|
||||||
|
if log_type == "file":
|
||||||
# log is a file, read it
|
# log is a file, read it
|
||||||
if log_path == "systemd":
|
if not os.path.isdir(log_path):
|
||||||
result[log_path] = _get_journalctl_logs(name, int(number)).splitlines()
|
|
||||||
continue
|
|
||||||
elif not os.path.isdir(log_path):
|
|
||||||
result[log_path] = _tail(log_path, int(number)) if os.path.exists(log_path) else []
|
result[log_path] = _tail(log_path, int(number)) if os.path.exists(log_path) else []
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -392,6 +407,9 @@ def service_log(name, number=50):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result[log_file_path] = _tail(log_file_path, int(number)) if os.path.exists(log_file_path) else []
|
result[log_file_path] = _tail(log_file_path, int(number)) if os.path.exists(log_file_path) else []
|
||||||
|
else:
|
||||||
|
# get log with journalctl
|
||||||
|
result[log_path] = _get_journalctl_logs(log_path, int(number)).splitlines()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue