Compare commits

...

4 commits

Author SHA1 Message Date
40b853d71a [d] Fix bug on restart 2018-09-21 16:39:20 +02:00
9c5a8f4379 [D] fix doit restart 2018-09-21 12:35:33 +02:00
cf3163979a doit supports concurrent tasks 2018-09-21 12:13:27 +02:00
c64ce844d1 [d] Adding a target to doit to restart containers 2018-09-20 23:43:23 +02:00

37
dodo.py
View file

@ -1,5 +1,6 @@
import subprocess import subprocess
import os import os
import sys
from doit.tools import LongRunning from doit.tools import LongRunning
@ -8,7 +9,7 @@ from dodo_utils import wait_net_service, wait_pgsql_db, \
run_task_func, scan_dir run_task_func, scan_dir
COMPOSE = 'docker-compose -p feedati' COMPOSE = 'docker-compose -p feedati'
DOIT_CONFIG = {'default_tasks': ['up']} DOIT_CONFIG = {'default_tasks': ['up'], 'backend': 'sqlite3'}
def task_build(): def task_build():
@ -104,6 +105,40 @@ def task_up():
} }
def _get_valid_services():
srv = subprocess.check_output((COMPOSE + ' config --services').split())
return srv.decode('utf-8').strip().split()
def restart(services):
'''This actually restart the container(s).'''
valid = _get_valid_services()
err = False
for service in services:
if service not in valid:
print('ERROR: invalid service %s' % service, file=sys.stderr)
err = True
if err or not services:
print('Valid services are: ' + ', '.join(valid), file=sys.stderr)
return False
for service in services:
subprocess.check_call((COMPOSE + ' restart %s' % service).split())
return True
def task_restart():
'''Restarts a container specified via commandline.'''
return {
'params': [{'name': 'services',
'short': 's',
'long': 'service',
'type': list,
'default': [],
'help': "the list of services to be restarted"}],
'actions': [(restart, )],
}
def task__cleanall(): def task__cleanall():
'''clean everything there is to clean''' '''clean everything there is to clean'''
return { return {