Ensure exit codes are propagated

This commit is contained in:
Einar Forselv 2019-12-03 07:36:48 +01:00
parent ed46a472a1
commit 2a861b0519
3 changed files with 23 additions and 7 deletions

View File

@ -53,5 +53,7 @@ def run(image: str = None, command: str = None, volumes: dict = None,
container.reload()
logger.info("Container ExitCode %s", container.attrs['State']['ExitCode'])
logger.debug("Container ExitCode %s", container.attrs['State']['ExitCode'])
container.remove()
return container.attrs['State']['ExitCode']

View File

@ -73,7 +73,7 @@ def backup(config, containers):
mounts = containers.generate_backup_mounts('/backup')
volumes.update(mounts)
backup_runner.run(
result = backup_runner.run(
image=containers.this_container.image,
command='restic-volume-backup start-backup-process',
volumes=volumes,
@ -84,6 +84,8 @@ def backup(config, containers):
"com.docker.compose.project": containers.this_container.project_name,
},
)
logger.info('Backup container exit code: %s', result)
# TODO: Alert
def start_backup_process(config, containers):
@ -100,14 +102,26 @@ def start_backup_process(config, containers):
logger.info("start-backup-process")
# Back up volumes
restic.backup_files(config.repository, source='/backup')
try:
vol_result = restic.backup_files(config.repository, source='/backup')
logger.info('Volume backup exit code: %s', vol_result)
# TODO: Alert
except Exception as ex:
logger.error(ex)
# TODO: Alert
# back up databases
for container in containers.containers_for_backup():
if container.database_backup_enabled:
instance = container.instance
logger.info('Backing up %s in service %s', instance.container_type, instance.service_name)
instance.backup()
try:
instance = container.instance
logger.info('Backing up %s in service %s', instance.container_type, instance.service_name)
result = instance.backup()
logger.info('Exit code: %s', result)
# TODO: Alert
except Exception as ex:
logger.error(ex)
# TODO: Alert
def parse_args():

View File

@ -46,7 +46,7 @@ def backup_from_stdin(repository: str, filename: str, source_command: List[str])
# Ensure both processes exited with code 0
source_exit, dest_exit = source_process.poll(), dest_process.poll()
return source_exit == 0 and dest_exit == 0
return 0 if (source_exit == 0 and dest_exit == 0) else 1
def snapshots(repository: str):