Skip to content

Commit

Permalink
Merge pull request #6209 from rogin/add-booter
Browse files Browse the repository at this point in the history
Implements #6208
  • Loading branch information
pladesma authored May 29, 2024
2 parents fa1c143 + 152d5a1 commit 89699f5
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion server/src/com/mirth/connect/server/Mirth.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Optional;
import java.util.Timer;
import java.util.TimerTask;

Expand All @@ -43,6 +44,7 @@
import com.mirth.connect.model.ResourceProperties;
import com.mirth.connect.model.ResourcePropertiesList;
import com.mirth.connect.model.ServerEvent;
import com.mirth.connect.model.ServerSettings;
import com.mirth.connect.model.UpdateSettings;
import com.mirth.connect.model.converters.ObjectXMLSerializer;
import com.mirth.connect.model.util.MigrationException;
Expand Down Expand Up @@ -338,12 +340,13 @@ public void startup() {
migrationController.clearStartupLockTable();
}

// disable the velocity logging
Logger velocityLogger = LogManager.getLogger(RuntimeConstants.DEFAULT_RUNTIME_LOG_NAME);
if (velocityLogger != null && velocityLogger.getLevel() == null && velocityLogger instanceof org.apache.logging.log4j.core.Logger) {
((org.apache.logging.log4j.core.Logger) velocityLogger).setLevel(Level.OFF);
}

updateServerSettingsFromEnvironment();

eventController.dispatchEvent(new ServerEvent(configurationController.getServerId(), "Server startup"));

// Start web server before starting the engine in case there is a
Expand Down Expand Up @@ -404,7 +407,35 @@ public void startup() {
timer.schedule(new UsageSenderTask(), 0, ConnectServiceUtil.MILLIS_PER_DAY);
}

private void updateServerSettingsFromEnvironment() {
Optional<String> newServerName = getEnvironmentVariable("MC_SERVER_NAME");
Optional<String> newEnvName = getEnvironmentVariable("MC_ENV_NAME");

if(newServerName.isPresent() || newEnvName.isPresent()) {
try {
ServerSettings serverSettings = configurationController.getServerSettings();

if(newServerName.isPresent()) { serverSettings.setServerName(newServerName.get()); }
if(newEnvName.isPresent()) { serverSettings.setEnvironmentName(newEnvName.get()); }

configurationController.setServerSettings(serverSettings);
} catch (ControllerException e) {
logger.error("Failed to update server settings via environment variables", e);
}
}
}

/**
* Pull an environment variable. Values are trimmed to a non-empty string.
* @param name
* @return
*/
private Optional<String> getEnvironmentVariable(String name) {
String propValue = StringUtils.trimToEmpty(System.getenv(name));
return StringUtils.isNotBlank(propValue) ? Optional.of(propValue) : Optional.empty();
}

/**
* Shuts down the server.
*
*/
Expand Down

0 comments on commit 89699f5

Please sign in to comment.