Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: ff48a8d8 by Tony Chemit at 2023-06-19T14:24:51+02:00 Le fichier de configuration du serveur n'est pas consistent - Closes #2735 - - - - - b927d0be by Tony Chemit at 2023-06-19T14:53:49+02:00 Ne pas regénérer le fichier de configuration des logs sur le serveur si celui contient déjà la bonne version - Closes #2736 - - - - - 1 changed file: - server/configuration/src/main/java/fr/ird/observe/server/configuration/ServerConfig.java Changes: ===================================== server/configuration/src/main/java/fr/ird/observe/server/configuration/ServerConfig.java ===================================== @@ -37,6 +37,7 @@ import org.apache.logging.log4j.Logger; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; @@ -103,10 +104,10 @@ public class ServerConfig extends GeneratedServerConfig implements CleanTemporar Path directory = Files.createTempDirectory("taiste"); ApplicationConfigInit init = ApplicationConfigInit .forAllScopesWithout(ApplicationConfigScope.CURRENT, - ApplicationConfigScope.HOME, - ApplicationConfigScope.ENV, - ApplicationConfigScope.CLASS_PATH, - ApplicationConfigScope.SYSTEM) + ApplicationConfigScope.HOME, + ApplicationConfigScope.ENV, + ApplicationConfigScope.CLASS_PATH, + ApplicationConfigScope.SYSTEM) .addDefaults(ServerConfigOption.CONTEXT_PATH.getKey(), "observe-${build.version}") .addDefaults(ServerConfigOption.COMMON_CONFIG_DIRECTORY.getKey(), String.format("%s/${build.version.major}", directory.resolve("conf"))) .addDefaults(ServerConfigOption.COMMON_INSTANCES_DIRECTORY.getKey(), directory.resolve("instances").toString()); @@ -165,17 +166,19 @@ public class ServerConfig extends GeneratedServerConfig implements CleanTemporar parse(); Path baseDirectory = getBaseDirectory().toPath(); - log.info(getConfigurationDescription()); createDirectories(baseDirectory, "Could not create application instance directory (%s)"); File extraConfigFile = get().getExtraConfigFile(); - if (Files.notExists(extraConfigFile.toPath())) { - boolean generated = ServerResources.APPLICATION_CONFIGURATION.setForWindows(isWindows()).copyResource(getCommonConfigurationFile().toPath(), extraConfigFile); - if (generated) { - log.info(String.format("Generate empty configuration file to: %s", extraConfigFile)); - } else { - log.info(String.format("Create symbolic link from common configuration file to: %s", extraConfigFile)); - } + + // store the configuration on extra config file to have correct options linked to the current build + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2735 + + log.info(String.format("Save instance configuration file to: %s", extraConfigFile)); + ConfigHelper.save(get(), extraConfigFile, new String[0], ServerResources.APPLICATION_CONFIGURATION, options()); + + if (log.isInfoEnabled()) { + String message = getConfigurationDescription(); + log.info(message); } Path temporaryDirectory = getTemporaryDirectory().toPath(); @@ -225,10 +228,22 @@ public class ServerConfig extends GeneratedServerConfig implements CleanTemporar private void initLog() { File log4jConfigurationFile = getLog4jConfigurationFile(); - try { - Files.deleteIfExists(log4jConfigurationFile.toPath()); - } catch (IOException e) { - throw new RuntimeException(e); + if (Files.exists(log4jConfigurationFile.toPath())) { + // check if version is the same as the instance one, if not then delete configuration file, otherwise keep it + // to be able to modify it before redeploying the instance + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2736 + try { + String content = Files.readString(log4jConfigurationFile.toPath(), StandardCharsets.UTF_8); + if (!content.contains("observe-server-" + getBuildVersion() + ".log\"")) { + // We need to delete the configuration file, build version mismatch + log.info("Delete previous log configuration file ({}) since the build version is not the same as the instance one ({})", log4jConfigurationFile, getBuildVersion()); + Files.deleteIfExists(log4jConfigurationFile.toPath()); + } else { + log.info("Keep previous log configuration file ({}) since the build version is the same as the instance one ({})", log4jConfigurationFile, getBuildVersion()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } } log.info(String.format("Chargement du fichier de log : %s", log4jConfigurationFile)); ObserveUtil.loadLogConfiguration(ServerResources.LOG_CONFIGURATION, getCommonLog4jConfigurationFile().toPath(), log4jConfigurationFile.toPath(), this); View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/a057723b741495da5ffae2520... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/a057723b741495da5ffae2520... You're receiving this email because of your account on gitlab.com.