Skip to content

docker-compose restart ought to exit with non-zero if it didn't actually restart #1236

Closed

Description

@iffy

If you have no containers running and you do docker-compose restart it exits with 0. It failed to restart so it should exit with non-zero. This will let you do something like:

docker-compose restart || docker-compose up -d

Activity

  1. seguins commented on Nov 10, 2015

    @seguins

    #44 says start / stop should be more verbose, maybe we can have the same things for start, stop, restart :

    • if nothing to do : returns an displayed error and exits with non-zero
    • if something to do : displays the action and exits with zero

    And what about pause, unpause, kill ? Should we have the same behavior ?

  2. dbonev commented on Dec 12, 2015

    @dbonev

    I can do that.

    In terms of error message, I was thinking something along the lines of:

    docker-compose restart
    ERROR: No containers to restart.
    

    The same behaviour could work for stop, pause, unpause.

    I'm not quite sure it's the right thing to do in the case of kill and rm though, as that would break lots of test because

    self.project.kill()
    self.project.remove_stopped()
    

    is part of tearDown() and that would make lots of tests fail.

  3. dnephin commented on Dec 14, 2015

    @dnephin

    I think it makes sense for restart, start, pause, and unpause.

    I think kill, stop and rm don't need to error because the desired state is reached. If you run rm and there is nothing to remove, I wouldn't consider that an error (same idea with kill and stop)

  4. dbonev commented on Dec 15, 2015

    @dbonev

    Thanks. It makes sense.

    There is a small issue with start though: In a few places in the test suite we have code where we call project.start() on a freshly created project and then explicitly test for containers count to be 0.

    Something like this (lines 220 / 221) (taken directly from https://github.com/docker/compose/blob/master/tests/integration/project_test.py#L220).

    216     def test_project_up(self):
    217         web = self.create_service('web')
    218         db = self.create_service('db', volumes=[VolumeSpec.parse('/var/db')])
    219         project = Project('composetest', [web, db], self.client)
    220         project.start()
    221         self.assertEqual(len(project.containers()), 0)
    

    Should we:
    a) fix the tests (I count 13 such places) to not call project.start() if nothing to start;
    b) leave start with the current behaviour;

    Thanks

  5. dnephin commented on Dec 15, 2015

    @dnephin

    I have no idea why these tests are calling project.start(). I think we should remove it, but I also don't think it needs to be done for this change. I would think the warning would be implemented as part of the compose/cli/main.py module instead of in project, since it's more of a concern for the cli.

    Right now project.start(), etc return nothing. I think we could have these methods return a list of containers they started, restarted, etc (or at least a count). Then the cli layer can print the warning and exit with the right status code (or maybe just raise an exception and let the existing exception handled do that).

  6. dbonev commented on Dec 15, 2015

    @dbonev

    @dnephin Thanks. Did it this way and submitted a PR. No impact on the tests (except adding a few more to test the new behaviour).
    Please let me know if something doesn't quite look right.
    Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions