Skip to content

Commit

Permalink
Add forced start mode for Docker Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Apr 4, 2024
1 parent e9e2bc9 commit eed489b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -119,7 +119,10 @@ void start() {
Wait wait = this.properties.getReadiness().getWait();
List<RunningService> runningServices = dockerCompose.getRunningServices();
if (lifecycleManagement.shouldStart()) {
if (runningServices.isEmpty()) {
if (!runningServices.isEmpty() && !start.isForce()) {
logger.info("There are already Docker Compose services running, skipping startup");
}
else {
start.getCommand().applyTo(dockerCompose, start.getLogLevel());
runningServices = dockerCompose.getRunningServices();
if (wait == Wait.ONLY_IF_STARTED) {
Expand All @@ -129,9 +132,6 @@ void start() {
this.shutdownHandlers.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout()));
}
}
else {
logger.info("There are already Docker Compose services running, skipping startup");
}
}
List<RunningService> relevantServices = new ArrayList<>(runningServices);
relevantServices.removeIf(this::isIgnored);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -148,6 +148,11 @@ public static class Start {
*/
private LogLevel logLevel = LogLevel.INFO;

/**
* Whether to force the start, regardless of running services.
*/
private boolean force;

public StartCommand getCommand() {
return this.command;
}
Expand All @@ -164,6 +169,14 @@ public void setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel;
}

public boolean isForce() {
return this.force;
}

public void setForce(boolean force) {
this.force = force;
}

}

/**
Expand Down

0 comments on commit eed489b

Please sign in to comment.