Skip to content
Snippets Groups Projects
Commit 301be6c56f6c authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: detect when script is not running anymore

parent 7d227ee3c120
No related branches found
No related tags found
No related merge requests found
......@@ -385,8 +385,9 @@
def signal_handler(code, frame):
if code == signal.SIGINT:
logging.debug('You pressed Ctrl+C!')
logging.info('Stopping odoo')
docker_client.stop(odoo.get('Id'))
if isRunning(docker_client, odoo.get('Id')):
logging.info('Stopping odoo')
docker_client.stop(odoo.get('Id'))
logging.info('Removing container odoo')
docker_client.remove_container(odoo.get('Id'))
if start_postgresql:
......@@ -401,7 +402,7 @@
# print docker logs of odoo
stream = docker_client.logs(odoo.get('Id'), stream=True, follow=True)
while True:
while isRunning(docker_client, odoo.get('Id')):
try:
for log in stream:
sys.stdout.write(log)
......@@ -411,7 +412,7 @@
pass
# Clean up, just in case
# signal_handler(signal.SIGINT, None)
signal_handler(signal.SIGINT, None)
# TODO add handling of signal to restart odoo
def getVolume(docker_client, data_volume_name):
......@@ -425,6 +426,11 @@
logging.debug('Creating volume %s', data_volume_name)
return docker_client.create_volume(name=data_volume_name)
def isRunning(docker_client, container_id):
"""Return true if the container is still running
"""
return len(docker_client.containers(filters={'id': container_id}, quiet=True))
if __name__ == "__main__":
return_code = main()
if return_code:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment