| ... |
... |
@@ -37,6 +37,7 @@ import org.apache.logging.log4j.Logger; |
|
37
|
37
|
|
|
38
|
38
|
import java.io.File;
|
|
39
|
39
|
import java.io.IOException;
|
|
|
40
|
+import java.nio.charset.StandardCharsets;
|
|
40
|
41
|
import java.nio.file.Files;
|
|
41
|
42
|
import java.nio.file.Path;
|
|
42
|
43
|
import java.util.Collections;
|
| ... |
... |
@@ -103,10 +104,10 @@ public class ServerConfig extends GeneratedServerConfig implements CleanTemporar |
|
103
|
104
|
Path directory = Files.createTempDirectory("taiste");
|
|
104
|
105
|
ApplicationConfigInit init = ApplicationConfigInit
|
|
105
|
106
|
.forAllScopesWithout(ApplicationConfigScope.CURRENT,
|
|
106
|
|
- ApplicationConfigScope.HOME,
|
|
107
|
|
- ApplicationConfigScope.ENV,
|
|
108
|
|
- ApplicationConfigScope.CLASS_PATH,
|
|
109
|
|
- ApplicationConfigScope.SYSTEM)
|
|
|
107
|
+ ApplicationConfigScope.HOME,
|
|
|
108
|
+ ApplicationConfigScope.ENV,
|
|
|
109
|
+ ApplicationConfigScope.CLASS_PATH,
|
|
|
110
|
+ ApplicationConfigScope.SYSTEM)
|
|
110
|
111
|
.addDefaults(ServerConfigOption.CONTEXT_PATH.getKey(), "observe-${build.version}")
|
|
111
|
112
|
.addDefaults(ServerConfigOption.COMMON_CONFIG_DIRECTORY.getKey(), String.format("%s/${build.version.major}", directory.resolve("conf")))
|
|
112
|
113
|
.addDefaults(ServerConfigOption.COMMON_INSTANCES_DIRECTORY.getKey(), directory.resolve("instances").toString());
|
| ... |
... |
@@ -165,17 +166,19 @@ public class ServerConfig extends GeneratedServerConfig implements CleanTemporar |
|
165
|
166
|
parse();
|
|
166
|
167
|
|
|
167
|
168
|
Path baseDirectory = getBaseDirectory().toPath();
|
|
168
|
|
- log.info(getConfigurationDescription());
|
|
169
|
169
|
createDirectories(baseDirectory, "Could not create application instance directory (%s)");
|
|
170
|
170
|
|
|
171
|
171
|
File extraConfigFile = get().getExtraConfigFile();
|
|
172
|
|
- if (Files.notExists(extraConfigFile.toPath())) {
|
|
173
|
|
- boolean generated = ServerResources.APPLICATION_CONFIGURATION.setForWindows(isWindows()).copyResource(getCommonConfigurationFile().toPath(), extraConfigFile);
|
|
174
|
|
- if (generated) {
|
|
175
|
|
- log.info(String.format("Generate empty configuration file to: %s", extraConfigFile));
|
|
176
|
|
- } else {
|
|
177
|
|
- log.info(String.format("Create symbolic link from common configuration file to: %s", extraConfigFile));
|
|
178
|
|
- }
|
|
|
172
|
+
|
|
|
173
|
+ // store the configuration on extra config file to have correct options linked to the current build
|
|
|
174
|
+ // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2735
|
|
|
175
|
+
|
|
|
176
|
+ log.info(String.format("Save instance configuration file to: %s", extraConfigFile));
|
|
|
177
|
+ ConfigHelper.save(get(), extraConfigFile, new String[0], ServerResources.APPLICATION_CONFIGURATION, options());
|
|
|
178
|
+
|
|
|
179
|
+ if (log.isInfoEnabled()) {
|
|
|
180
|
+ String message = getConfigurationDescription();
|
|
|
181
|
+ log.info(message);
|
|
179
|
182
|
}
|
|
180
|
183
|
|
|
181
|
184
|
Path temporaryDirectory = getTemporaryDirectory().toPath();
|
| ... |
... |
@@ -225,10 +228,22 @@ public class ServerConfig extends GeneratedServerConfig implements CleanTemporar |
|
225
|
228
|
|
|
226
|
229
|
private void initLog() {
|
|
227
|
230
|
File log4jConfigurationFile = getLog4jConfigurationFile();
|
|
228
|
|
- try {
|
|
229
|
|
- Files.deleteIfExists(log4jConfigurationFile.toPath());
|
|
230
|
|
- } catch (IOException e) {
|
|
231
|
|
- throw new RuntimeException(e);
|
|
|
231
|
+ if (Files.exists(log4jConfigurationFile.toPath())) {
|
|
|
232
|
+ // check if version is the same as the instance one, if not then delete configuration file, otherwise keep it
|
|
|
233
|
+ // to be able to modify it before redeploying the instance
|
|
|
234
|
+ // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2736
|
|
|
235
|
+ try {
|
|
|
236
|
+ String content = Files.readString(log4jConfigurationFile.toPath(), StandardCharsets.UTF_8);
|
|
|
237
|
+ if (!content.contains("observe-server-" + getBuildVersion() + ".log\"")) {
|
|
|
238
|
+ // We need to delete the configuration file, build version mismatch
|
|
|
239
|
+ log.info("Delete previous log configuration file ({}) since the build version is not the same as the instance one ({})", log4jConfigurationFile, getBuildVersion());
|
|
|
240
|
+ Files.deleteIfExists(log4jConfigurationFile.toPath());
|
|
|
241
|
+ } else {
|
|
|
242
|
+ log.info("Keep previous log configuration file ({}) since the build version is the same as the instance one ({})", log4jConfigurationFile, getBuildVersion());
|
|
|
243
|
+ }
|
|
|
244
|
+ } catch (IOException e) {
|
|
|
245
|
+ throw new RuntimeException(e);
|
|
|
246
|
+ }
|
|
232
|
247
|
}
|
|
233
|
248
|
log.info(String.format("Chargement du fichier de log : %s", log4jConfigurationFile));
|
|
234
|
249
|
ObserveUtil.loadLogConfiguration(ServerResources.LOG_CONFIGURATION, getCommonLog4jConfigurationFile().toPath(), log4jConfigurationFile.toPath(), this);
|