Skip to content

Commit 6a06a5b

Browse files
dkayiwaCopilot
andauthored
Fix shutdown cleanup: stop Tomcat before MariaDB, disable reloadable (#115)
- Change shutdown hook order to stop Tomcat first, then MariaDB, ensuring Tomcat can cleanly finish context cleanup before the database is killed - Set context reloadable=false since hot-reloading is unnecessary for a standalone distribution and causes extra file monitoring - Call container.destroy() after container.stop() for proper Tomcat lifecycle cleanup Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fb30d61 commit 6a06a5b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/main/java/org/openmrs/standalone/ApplicationController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,17 @@ private void init(boolean commandLineMode, boolean nonInteractive, DatabaseMode
234234

235235
userInterface.setVisible(true);
236236

237-
// add shutdown hook to stop server
237+
// add shutdown hook to stop server (Tomcat first, then MariaDB)
238238
Runtime.getRuntime().addShutdownHook(new Thread() {
239239

240240
public void run() {
241+
stopServer();
241242
try {
242243
stopMariaDB();
243244
} catch (ManagedProcessException e) {
244245
System.out.println("Failed to stop MariaDB: " + e.getMessage());
245246
e.printStackTrace();
246247
}
247-
stopServer();
248248
}
249249
});
250250

src/main/java/org/openmrs/standalone/TomcatManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public TomcatManager(String contextName, int port) {
7474
String warPath = "tomcat/webapps/" + contextName + ".war";
7575
File warFile = new File(warPath);
7676
Context rootContext = container.addWebapp("/" + contextName, warFile.getAbsolutePath());
77-
rootContext.setReloadable(true);
77+
rootContext.setReloadable(false);
7878

7979
// create http connector
8080
Connector httpConnector = new Connector();
@@ -101,6 +101,7 @@ public boolean stop() {
101101
try {
102102
if (container != null) {
103103
container.stop();
104+
container.destroy();
104105
container = null;
105106
stopMySql = true;
106107
}

0 commit comments

Comments
 (0)