main.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. from __future__ import absolute_import
  2. from __future__ import print_function
  3. from __future__ import unicode_literals
  4. import json
  5. import logging
  6. import re
  7. import sys
  8. from inspect import getdoc
  9. from operator import attrgetter
  10. import yaml
  11. from docker.errors import APIError
  12. from requests.exceptions import ReadTimeout
  13. from . import signals
  14. from .. import __version__
  15. from ..config import config
  16. from ..config import ConfigurationError
  17. from ..config import parse_environment
  18. from ..const import DEFAULT_TIMEOUT
  19. from ..const import HTTP_TIMEOUT
  20. from ..const import IS_WINDOWS_PLATFORM
  21. from ..progress_stream import StreamOutputError
  22. from ..project import NoSuchService
  23. from ..service import BuildError
  24. from ..service import ConvergenceStrategy
  25. from ..service import ImageType
  26. from ..service import NeedsBuildError
  27. from .command import friendly_error_message
  28. from .command import get_config_path_from_options
  29. from .command import project_from_options
  30. from .docopt_command import DocoptCommand
  31. from .docopt_command import NoSuchCommand
  32. from .errors import UserError
  33. from .formatter import ConsoleWarningFormatter
  34. from .formatter import Formatter
  35. from .log_printer import LogPrinter
  36. from .utils import get_version_info
  37. from .utils import yesno
  38. if not IS_WINDOWS_PLATFORM:
  39. import dockerpty
  40. log = logging.getLogger(__name__)
  41. console_handler = logging.StreamHandler(sys.stderr)
  42. def main():
  43. setup_logging()
  44. try:
  45. command = TopLevelCommand()
  46. command.sys_dispatch()
  47. except KeyboardInterrupt:
  48. log.error("\nAborting.")
  49. sys.exit(1)
  50. except (UserError, NoSuchService, ConfigurationError) as e:
  51. log.error(e.msg)
  52. sys.exit(1)
  53. except NoSuchCommand as e:
  54. commands = "\n".join(parse_doc_section("commands:", getdoc(e.supercommand)))
  55. log.error("No such command: %s\n\n%s", e.command, commands)
  56. sys.exit(1)
  57. except APIError as e:
  58. log.error(e.explanation)
  59. sys.exit(1)
  60. except BuildError as e:
  61. log.error("Service '%s' failed to build: %s" % (e.service.name, e.reason))
  62. sys.exit(1)
  63. except StreamOutputError as e:
  64. log.error(e)
  65. sys.exit(1)
  66. except NeedsBuildError as e:
  67. log.error("Service '%s' needs to be built, but --no-build was passed." % e.service.name)
  68. sys.exit(1)
  69. except ReadTimeout as e:
  70. log.error(
  71. "An HTTP request took too long to complete. Retry with --verbose to obtain debug information.\n"
  72. "If you encounter this issue regularly because of slow network conditions, consider setting "
  73. "COMPOSE_HTTP_TIMEOUT to a higher value (current value: %s)." % HTTP_TIMEOUT
  74. )
  75. sys.exit(1)
  76. def setup_logging():
  77. root_logger = logging.getLogger()
  78. root_logger.addHandler(console_handler)
  79. root_logger.setLevel(logging.DEBUG)
  80. # Disable requests logging
  81. logging.getLogger("requests").propagate = False
  82. def setup_console_handler(handler, verbose):
  83. if handler.stream.isatty():
  84. format_class = ConsoleWarningFormatter
  85. else:
  86. format_class = logging.Formatter
  87. if verbose:
  88. handler.setFormatter(format_class('%(name)s.%(funcName)s: %(message)s'))
  89. handler.setLevel(logging.DEBUG)
  90. else:
  91. handler.setFormatter(format_class())
  92. handler.setLevel(logging.INFO)
  93. # stolen from docopt master
  94. def parse_doc_section(name, source):
  95. pattern = re.compile('^([^\n]*' + name + '[^\n]*\n?(?:[ \t].*?(?:\n|$))*)',
  96. re.IGNORECASE | re.MULTILINE)
  97. return [s.strip() for s in pattern.findall(source)]
  98. class TopLevelCommand(DocoptCommand):
  99. """Define and run multi-container applications with Docker.
  100. Usage:
  101. docker-compose [-f=<arg>...] [options] [COMMAND] [ARGS...]
  102. docker-compose -h|--help
  103. Options:
  104. -f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
  105. -p, --project-name NAME Specify an alternate project name (default: directory name)
  106. --verbose Show more output
  107. -v, --version Print version and exit
  108. Commands:
  109. build Build or rebuild services
  110. config Validate and view the compose file
  111. create Create services
  112. down Stop and remove containers, networks, images, and volumes
  113. events Receive real time events from containers
  114. help Get help on a command
  115. kill Kill containers
  116. logs View output from containers
  117. pause Pause services
  118. port Print the public port for a port binding
  119. ps List containers
  120. pull Pulls service images
  121. restart Restart services
  122. rm Remove stopped containers
  123. run Run a one-off command
  124. scale Set number of containers for a service
  125. start Start services
  126. stop Stop services
  127. unpause Unpause services
  128. up Create and start containers
  129. version Show the Docker-Compose version information
  130. """
  131. base_dir = '.'
  132. def docopt_options(self):
  133. options = super(TopLevelCommand, self).docopt_options()
  134. options['version'] = get_version_info('compose')
  135. return options
  136. def perform_command(self, options, handler, command_options):
  137. setup_console_handler(console_handler, options.get('--verbose'))
  138. if options['COMMAND'] in ('help', 'version'):
  139. # Skip looking up the compose file.
  140. handler(None, command_options)
  141. return
  142. if options['COMMAND'] == 'config':
  143. handler(options, command_options)
  144. return
  145. project = project_from_options(self.base_dir, options)
  146. with friendly_error_message():
  147. handler(project, command_options)
  148. def build(self, project, options):
  149. """
  150. Build or rebuild services.
  151. Services are built once and then tagged as `project_service`,
  152. e.g. `composetest_db`. If you change a service's `Dockerfile` or the
  153. contents of its build directory, you can run `docker-compose build` to rebuild it.
  154. Usage: build [options] [SERVICE...]
  155. Options:
  156. --force-rm Always remove intermediate containers.
  157. --no-cache Do not use cache when building the image.
  158. --pull Always attempt to pull a newer version of the image.
  159. """
  160. project.build(
  161. service_names=options['SERVICE'],
  162. no_cache=bool(options.get('--no-cache', False)),
  163. pull=bool(options.get('--pull', False)),
  164. force_rm=bool(options.get('--force-rm', False)))
  165. def config(self, config_options, options):
  166. """
  167. Validate and view the compose file.
  168. Usage: config [options]
  169. Options:
  170. -q, --quiet Only validate the configuration, don't print
  171. anything.
  172. --services Print the service names, one per line.
  173. """
  174. config_path = get_config_path_from_options(config_options)
  175. compose_config = config.load(config.find(self.base_dir, config_path))
  176. if options['--quiet']:
  177. return
  178. if options['--services']:
  179. print('\n'.join(service['name'] for service in compose_config.services))
  180. return
  181. compose_config = dict(
  182. (service.pop('name'), service) for service in compose_config.services)
  183. print(yaml.dump(
  184. compose_config,
  185. default_flow_style=False,
  186. indent=2,
  187. width=80))
  188. def create(self, project, options):
  189. """
  190. Creates containers for a service.
  191. Usage: create [options] [SERVICE...]
  192. Options:
  193. --force-recreate Recreate containers even if their configuration and
  194. image haven't changed. Incompatible with --no-recreate.
  195. --no-recreate If containers already exist, don't recreate them.
  196. Incompatible with --force-recreate.
  197. --no-build Don't build an image, even if it's missing
  198. """
  199. service_names = options['SERVICE']
  200. project.create(
  201. service_names=service_names,
  202. strategy=convergence_strategy_from_opts(options),
  203. do_build=not options['--no-build']
  204. )
  205. def down(self, project, options):
  206. """
  207. Stop containers and remove containers, networks, volumes, and images
  208. created by `up`.
  209. Usage: down [options]
  210. Options:
  211. --rmi type Remove images, type may be one of: 'all' to remove
  212. all images, or 'local' to remove only images that
  213. don't have an custom name set by the `image` field
  214. -v, --volumes Remove data volumes
  215. """
  216. image_type = image_type_from_opt('--rmi', options['--rmi'])
  217. project.down(image_type, options['--volumes'])
  218. def events(self, project, options):
  219. """
  220. Receive real time events from containers.
  221. Usage: events [options] [SERVICE...]
  222. Options:
  223. --json Output events as a stream of json objects
  224. """
  225. def format_event(event):
  226. attributes = ["%s=%s" % item for item in event['attributes'].items()]
  227. return ("{time} {type} {action} {id} ({attrs})").format(
  228. attrs=", ".join(sorted(attributes)),
  229. **event)
  230. def json_format_event(event):
  231. event['time'] = event['time'].isoformat()
  232. return json.dumps(event)
  233. for event in project.events():
  234. formatter = json_format_event if options['--json'] else format_event
  235. print(formatter(event))
  236. sys.stdout.flush()
  237. def help(self, project, options):
  238. """
  239. Get help on a command.
  240. Usage: help COMMAND
  241. """
  242. handler = self.get_handler(options['COMMAND'])
  243. raise SystemExit(getdoc(handler))
  244. def kill(self, project, options):
  245. """
  246. Force stop service containers.
  247. Usage: kill [options] [SERVICE...]
  248. Options:
  249. -s SIGNAL SIGNAL to send to the container.
  250. Default signal is SIGKILL.
  251. """
  252. signal = options.get('-s', 'SIGKILL')
  253. project.kill(service_names=options['SERVICE'], signal=signal)
  254. def logs(self, project, options):
  255. """
  256. View output from containers.
  257. Usage: logs [options] [SERVICE...]
  258. Options:
  259. --no-color Produce monochrome output.
  260. """
  261. containers = project.containers(service_names=options['SERVICE'], stopped=True)
  262. monochrome = options['--no-color']
  263. print("Attaching to", list_containers(containers))
  264. LogPrinter(containers, monochrome=monochrome).run()
  265. def pause(self, project, options):
  266. """
  267. Pause services.
  268. Usage: pause [SERVICE...]
  269. """
  270. containers = project.pause(service_names=options['SERVICE'])
  271. exit_if(not containers, 'No containers to pause', 1)
  272. def port(self, project, options):
  273. """
  274. Print the public port for a port binding.
  275. Usage: port [options] SERVICE PRIVATE_PORT
  276. Options:
  277. --protocol=proto tcp or udp [default: tcp]
  278. --index=index index of the container if there are multiple
  279. instances of a service [default: 1]
  280. """
  281. index = int(options.get('--index'))
  282. service = project.get_service(options['SERVICE'])
  283. try:
  284. container = service.get_container(number=index)
  285. except ValueError as e:
  286. raise UserError(str(e))
  287. print(container.get_local_port(
  288. options['PRIVATE_PORT'],
  289. protocol=options.get('--protocol') or 'tcp') or '')
  290. def ps(self, project, options):
  291. """
  292. List containers.
  293. Usage: ps [options] [SERVICE...]
  294. Options:
  295. -q Only display IDs
  296. """
  297. containers = sorted(
  298. project.containers(service_names=options['SERVICE'], stopped=True) +
  299. project.containers(service_names=options['SERVICE'], one_off=True),
  300. key=attrgetter('name'))
  301. if options['-q']:
  302. for container in containers:
  303. print(container.id)
  304. else:
  305. headers = [
  306. 'Name',
  307. 'Command',
  308. 'State',
  309. 'Ports',
  310. ]
  311. rows = []
  312. for container in containers:
  313. command = container.human_readable_command
  314. if len(command) > 30:
  315. command = '%s ...' % command[:26]
  316. rows.append([
  317. container.name,
  318. command,
  319. container.human_readable_state,
  320. container.human_readable_ports,
  321. ])
  322. print(Formatter().table(headers, rows))
  323. def pull(self, project, options):
  324. """
  325. Pulls images for services.
  326. Usage: pull [options] [SERVICE...]
  327. Options:
  328. --ignore-pull-failures Pull what it can and ignores images with pull failures.
  329. """
  330. project.pull(
  331. service_names=options['SERVICE'],
  332. ignore_pull_failures=options.get('--ignore-pull-failures')
  333. )
  334. def rm(self, project, options):
  335. """
  336. Remove stopped service containers.
  337. By default, volumes attached to containers will not be removed. You can see all
  338. volumes with `docker volume ls`.
  339. Any data which is not in a volume will be lost.
  340. Usage: rm [options] [SERVICE...]
  341. Options:
  342. -f, --force Don't ask to confirm removal
  343. -v Remove volumes associated with containers
  344. """
  345. all_containers = project.containers(service_names=options['SERVICE'], stopped=True)
  346. stopped_containers = [c for c in all_containers if not c.is_running]
  347. if len(stopped_containers) > 0:
  348. print("Going to remove", list_containers(stopped_containers))
  349. if options.get('--force') \
  350. or yesno("Are you sure? [yN] ", default=False):
  351. project.remove_stopped(
  352. service_names=options['SERVICE'],
  353. v=options.get('-v', False)
  354. )
  355. else:
  356. print("No stopped containers")
  357. def run(self, project, options):
  358. """
  359. Run a one-off command on a service.
  360. For example:
  361. $ docker-compose run web python manage.py shell
  362. By default, linked services will be started, unless they are already
  363. running. If you do not want to start linked services, use
  364. `docker-compose run --no-deps SERVICE COMMAND [ARGS...]`.
  365. Usage: run [options] [-p PORT...] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]
  366. Options:
  367. -d Detached mode: Run container in the background, print
  368. new container name.
  369. --name NAME Assign a name to the container
  370. --entrypoint CMD Override the entrypoint of the image.
  371. -e KEY=VAL Set an environment variable (can be used multiple times)
  372. -u, --user="" Run as specified username or uid
  373. --no-deps Don't start linked services.
  374. --rm Remove container after run. Ignored in detached mode.
  375. -p, --publish=[] Publish a container's port(s) to the host
  376. --service-ports Run command with the service's ports enabled and mapped
  377. to the host.
  378. -T Disable pseudo-tty allocation. By default `docker-compose run`
  379. allocates a TTY.
  380. """
  381. service = project.get_service(options['SERVICE'])
  382. detach = options['-d']
  383. if IS_WINDOWS_PLATFORM and not detach:
  384. raise UserError(
  385. "Interactive mode is not yet supported on Windows.\n"
  386. "Please pass the -d flag when using `docker-compose run`."
  387. )
  388. if options['COMMAND']:
  389. command = [options['COMMAND']] + options['ARGS']
  390. else:
  391. command = service.options.get('command')
  392. container_options = {
  393. 'command': command,
  394. 'tty': not (detach or options['-T'] or not sys.stdin.isatty()),
  395. 'stdin_open': not detach,
  396. 'detach': detach,
  397. }
  398. if options['-e']:
  399. container_options['environment'] = parse_environment(options['-e'])
  400. if options['--entrypoint']:
  401. container_options['entrypoint'] = options.get('--entrypoint')
  402. if options['--rm']:
  403. container_options['restart'] = None
  404. if options['--user']:
  405. container_options['user'] = options.get('--user')
  406. if not options['--service-ports']:
  407. container_options['ports'] = []
  408. if options['--publish']:
  409. container_options['ports'] = options.get('--publish')
  410. if options['--publish'] and options['--service-ports']:
  411. raise UserError(
  412. 'Service port mapping and manual port mapping '
  413. 'can not be used togather'
  414. )
  415. if options['--name']:
  416. container_options['name'] = options['--name']
  417. run_one_off_container(container_options, project, service, options)
  418. def scale(self, project, options):
  419. """
  420. Set number of containers to run for a service.
  421. Numbers are specified in the form `service=num` as arguments.
  422. For example:
  423. $ docker-compose scale web=2 worker=3
  424. Usage: scale [options] [SERVICE=NUM...]
  425. Options:
  426. -t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
  427. (default: 10)
  428. """
  429. timeout = int(options.get('--timeout') or DEFAULT_TIMEOUT)
  430. for s in options['SERVICE=NUM']:
  431. if '=' not in s:
  432. raise UserError('Arguments to scale should be in the form service=num')
  433. service_name, num = s.split('=', 1)
  434. try:
  435. num = int(num)
  436. except ValueError:
  437. raise UserError('Number of containers for service "%s" is not a '
  438. 'number' % service_name)
  439. project.get_service(service_name).scale(num, timeout=timeout)
  440. def start(self, project, options):
  441. """
  442. Start existing containers.
  443. Usage: start [SERVICE...]
  444. """
  445. containers = project.start(service_names=options['SERVICE'])
  446. exit_if(not containers, 'No containers to start', 1)
  447. def stop(self, project, options):
  448. """
  449. Stop running containers without removing them.
  450. They can be started again with `docker-compose start`.
  451. Usage: stop [options] [SERVICE...]
  452. Options:
  453. -t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
  454. (default: 10)
  455. """
  456. timeout = int(options.get('--timeout') or DEFAULT_TIMEOUT)
  457. project.stop(service_names=options['SERVICE'], timeout=timeout)
  458. def restart(self, project, options):
  459. """
  460. Restart running containers.
  461. Usage: restart [options] [SERVICE...]
  462. Options:
  463. -t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
  464. (default: 10)
  465. """
  466. timeout = int(options.get('--timeout') or DEFAULT_TIMEOUT)
  467. containers = project.restart(service_names=options['SERVICE'], timeout=timeout)
  468. exit_if(not containers, 'No containers to restart', 1)
  469. def unpause(self, project, options):
  470. """
  471. Unpause services.
  472. Usage: unpause [SERVICE...]
  473. """
  474. containers = project.unpause(service_names=options['SERVICE'])
  475. exit_if(not containers, 'No containers to unpause', 1)
  476. def up(self, project, options):
  477. """
  478. Builds, (re)creates, starts, and attaches to containers for a service.
  479. Unless they are already running, this command also starts any linked services.
  480. The `docker-compose up` command aggregates the output of each container. When
  481. the command exits, all containers are stopped. Running `docker-compose up -d`
  482. starts the containers in the background and leaves them running.
  483. If there are existing containers for a service, and the service's configuration
  484. or image was changed after the container's creation, `docker-compose up` picks
  485. up the changes by stopping and recreating the containers (preserving mounted
  486. volumes). To prevent Compose from picking up changes, use the `--no-recreate`
  487. flag.
  488. If you want to force Compose to stop and recreate all containers, use the
  489. `--force-recreate` flag.
  490. Usage: up [options] [SERVICE...]
  491. Options:
  492. -d Detached mode: Run containers in the background,
  493. print new container names.
  494. Incompatible with --abort-on-container-exit.
  495. --no-color Produce monochrome output.
  496. --no-deps Don't start linked services.
  497. --force-recreate Recreate containers even if their configuration
  498. and image haven't changed.
  499. Incompatible with --no-recreate.
  500. --no-recreate If containers already exist, don't recreate them.
  501. Incompatible with --force-recreate.
  502. --no-build Don't build an image, even if it's missing
  503. --abort-on-container-exit Stops all containers if any container was stopped.
  504. Incompatible with -d.
  505. -t, --timeout TIMEOUT Use this timeout in seconds for container shutdown
  506. when attached or when containers are already
  507. running. (default: 10)
  508. """
  509. monochrome = options['--no-color']
  510. start_deps = not options['--no-deps']
  511. cascade_stop = options['--abort-on-container-exit']
  512. service_names = options['SERVICE']
  513. timeout = int(options.get('--timeout') or DEFAULT_TIMEOUT)
  514. detached = options.get('-d')
  515. if detached and cascade_stop:
  516. raise UserError("--abort-on-container-exit and -d cannot be combined.")
  517. to_attach = project.up(
  518. service_names=service_names,
  519. start_deps=start_deps,
  520. strategy=convergence_strategy_from_opts(options),
  521. do_build=not options['--no-build'],
  522. timeout=timeout,
  523. detached=detached
  524. )
  525. if not detached:
  526. log_printer = build_log_printer(to_attach, service_names, monochrome, cascade_stop)
  527. attach_to_logs(project, log_printer, service_names, timeout)
  528. def version(self, project, options):
  529. """
  530. Show version informations
  531. Usage: version [--short]
  532. Options:
  533. --short Shows only Compose's version number.
  534. """
  535. if options['--short']:
  536. print(__version__)
  537. else:
  538. print(get_version_info('full'))
  539. def convergence_strategy_from_opts(options):
  540. no_recreate = options['--no-recreate']
  541. force_recreate = options['--force-recreate']
  542. if force_recreate and no_recreate:
  543. raise UserError("--force-recreate and --no-recreate cannot be combined.")
  544. if force_recreate:
  545. return ConvergenceStrategy.always
  546. if no_recreate:
  547. return ConvergenceStrategy.never
  548. return ConvergenceStrategy.changed
  549. def image_type_from_opt(flag, value):
  550. if not value:
  551. return ImageType.none
  552. try:
  553. return ImageType[value]
  554. except KeyError:
  555. raise UserError("%s flag must be one of: all, local" % flag)
  556. def run_one_off_container(container_options, project, service, options):
  557. if not options['--no-deps']:
  558. deps = service.get_linked_service_names()
  559. if deps:
  560. project.up(
  561. service_names=deps,
  562. start_deps=True,
  563. strategy=ConvergenceStrategy.never)
  564. if project.use_networking:
  565. project.ensure_network_exists()
  566. container = service.create_container(
  567. quiet=True,
  568. one_off=True,
  569. **container_options)
  570. if options['-d']:
  571. container.start()
  572. print(container.name)
  573. return
  574. def remove_container(force=False):
  575. if options['--rm']:
  576. project.client.remove_container(container.id, force=True)
  577. signals.set_signal_handler_to_shutdown()
  578. try:
  579. try:
  580. dockerpty.start(project.client, container.id, interactive=not options['-T'])
  581. exit_code = container.wait()
  582. except signals.ShutdownException:
  583. project.client.stop(container.id)
  584. exit_code = 1
  585. except signals.ShutdownException:
  586. project.client.kill(container.id)
  587. remove_container(force=True)
  588. sys.exit(2)
  589. remove_container()
  590. sys.exit(exit_code)
  591. def build_log_printer(containers, service_names, monochrome, cascade_stop):
  592. if service_names:
  593. containers = [
  594. container
  595. for container in containers if container.service in service_names
  596. ]
  597. return LogPrinter(containers, monochrome=monochrome, cascade_stop=cascade_stop)
  598. def attach_to_logs(project, log_printer, service_names, timeout):
  599. print("Attaching to", list_containers(log_printer.containers))
  600. signals.set_signal_handler_to_shutdown()
  601. try:
  602. try:
  603. log_printer.run()
  604. except signals.ShutdownException:
  605. print("Gracefully stopping... (press Ctrl+C again to force)")
  606. project.stop(service_names=service_names, timeout=timeout)
  607. except signals.ShutdownException:
  608. project.kill(service_names=service_names)
  609. sys.exit(2)
  610. def list_containers(containers):
  611. return ", ".join(c.name for c in containers)
  612. def exit_if(condition, message, exit_code):
  613. if condition:
  614. log.error(message)
  615. raise SystemExit(exit_code)