mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Log special upgrade into operation_logger
This commit is contained in:
parent
096c2a7d7b
commit
ad0f65aad7
2 changed files with 23 additions and 9 deletions
|
@ -318,14 +318,27 @@ class OperationLogger(object):
|
|||
self.flush()
|
||||
self._register_log()
|
||||
|
||||
@property
|
||||
def md_path(self):
|
||||
"""
|
||||
Metadata path file
|
||||
"""
|
||||
return os.path.join(self.path, self.name + METADATA_FILE_EXT)
|
||||
|
||||
@property
|
||||
def log_path(self):
|
||||
"""
|
||||
Log path file
|
||||
"""
|
||||
return os.path.join(self.path, self.name + LOG_FILE_EXT)
|
||||
|
||||
def _register_log(self):
|
||||
"""
|
||||
Register log with a handler connected on log system
|
||||
"""
|
||||
|
||||
# TODO add a way to not save password on app installation
|
||||
filename = os.path.join(self.path, self.name + LOG_FILE_EXT)
|
||||
self.file_handler = FileHandler(filename)
|
||||
self.file_handler = FileHandler(self.log_path)
|
||||
self.file_handler.formatter = Formatter('%(asctime)s: %(levelname)s - %(message)s')
|
||||
|
||||
# Listen to the root logger
|
||||
|
@ -337,8 +350,7 @@ class OperationLogger(object):
|
|||
Write or rewrite the metadata file with all metadata known
|
||||
"""
|
||||
|
||||
filename = os.path.join(self.path, self.name + METADATA_FILE_EXT)
|
||||
with open(filename, 'w') as outfile:
|
||||
with open(self.md_path, 'w') as outfile:
|
||||
yaml.safe_dump(self.metadata, outfile, default_flow_style=False)
|
||||
|
||||
@property
|
||||
|
|
|
@ -660,18 +660,20 @@ def tools_upgrade(operation_logger, auth, ignore_apps=False, ignore_packages=Fal
|
|||
# likely to kill/restart the api which is in turn likely to kill this
|
||||
# command before it ends...)
|
||||
#
|
||||
|
||||
logfile = "/var/log/yunohost/special_upgrade_%s.log" % datetime.utcnow().strftime("%Y%m%d_%H%M%S")
|
||||
logfile = operation_logger.log_path
|
||||
command = dist_upgrade + " 2>&1 | tee -a {}".format(logfile)
|
||||
|
||||
MOULINETTE_LOCK = "/var/run/moulinette_yunohost.lock"
|
||||
wait_until_end_of_yunohost_command = "(while [ -f {} ]; do sleep 2; done)".format(MOULINETTE_LOCK)
|
||||
update_log_metadata = "sed -i \"s/ended_at: .*$/ended_at: $(date -u +'%Y-%m-%d %H:%M:%S.%N')/\" {}"
|
||||
update_log_metadata = update_log_metadata.format(operation_logger.md_path)
|
||||
|
||||
# TODO : i18n
|
||||
upgrade_completed = "YunoHost package upgrade completed ! Press [enter] to get the command line back"
|
||||
command = "({} && {}; echo '{}') &".format(wait_until_end_of_yunohost_command,
|
||||
command,
|
||||
upgrade_completed)
|
||||
command = "({} && {} && {}; echo '{}') &".format(wait_until_end_of_yunohost_command,
|
||||
command,
|
||||
update_log_metadata,
|
||||
upgrade_completed)
|
||||
|
||||
logger.debug("Running command :\n{}".format(command))
|
||||
os.system(command)
|
||||
|
|
Loading…
Add table
Reference in a new issue