-
Notifications
You must be signed in to change notification settings - Fork 88
/
stop.java
100 lines (88 loc) · 3.44 KB
/
stop.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* Controller script to stop the Keycloak environment.
*
* <h2>Stop Keycloak</h2>
* <pre>{@code
* java stop.java
* }</pre>
*/
class start {
static final String HELP_CMD = "help";
static final String VERBOSE_OPT = "--verbose";
public static void main(String[] args) throws IOException{
var argList = Arrays.asList(args);
var verbose = argList.contains(VERBOSE_OPT);
var showHelp = argList.contains(HELP_CMD);
if (showHelp) {
System.out.println("Keycloak Environment stopper");
System.out.println("");
System.exit(0);
}
System.out.println("### Stopping Keycloak Environment");
var commandLine = new ArrayList<String>();
commandLine.add("docker");
commandLine.add("compose");
var envFile = Paths.get("generated.env.tmp");
var useHttps = false;
if (Files.exists(envFile)) {
commandLine.add("--env-file");
commandLine.add("generated.env.tmp");
useHttps = Files.readString(envFile).contains("CA_ROOT_CERT=");
}
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose.yml");
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-keycloak.yml");
if (useHttps) {
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-tls.yml");
}
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-openldap.yml");
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-postgres.yml");
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-provisioning.yml");
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-graylog.yml");
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-prometheus.yml");
if (argList.contains("--skip=grafana")) {
// ignore grafana to fix invalid spec: :/etc/ssl/certs/ca-cert-acme-root.crt:z: empty section between colons
} else {
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-grafana.yml");
}
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-tracing.yml");
if (useHttps) {
commandLine.add("--file");
commandLine.add("deployments/local/dev/docker-compose-tracing-tls.yml");
}
commandLine.add("down");
commandLine.add("--remove-orphans");
commandLine.add("--volumes");
if (verbose) {
System.out.printf("Generated command: %n```%n%s%n```%n",
commandLine.stream().collect(Collectors.joining(" \\\n")));
}
var pb = new ProcessBuilder(commandLine);
pb.directory(new File("."));
pb.inheritIO();
try {
var process = pb.start();
System.exit(process.waitFor());
} catch (Exception ex) {
System.err.println("Could not run docker compose down.");
ex.printStackTrace();
System.exit(1);
}
}
}