Compare commits

...

2 commits

Author SHA1 Message Date
b5791e784b Add custom user to run the deployed apps
To prevent running them with the root user.
2023-05-21 22:24:01 +02:00
f3bcd64a90 Fix db pooling shutdown on web after startup 2023-05-21 22:23:22 +02:00
3 changed files with 15 additions and 5 deletions

View file

@ -8,6 +8,7 @@ services:
context: .
target: bot
restart: unless-stopped
user: 1000:1000
depends_on:
- db
- migration
@ -21,6 +22,7 @@ services:
context: .
target: web
restart: unless-stopped
user: 1000:1000
depends_on:
- db
- migration
@ -35,6 +37,7 @@ services:
dockerfile: Containerfile
context: .
target: migration
user: 1000:1000
depends_on:
- db

View file

@ -4,7 +4,6 @@ import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import de.hhhammer.dchat.db.ServerDBService;
import de.hhhammer.dchat.db.UserDBService;
import io.javalin.Javalin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -30,9 +29,6 @@ public class App {
config.setJdbcUrl(postgresUrl);
config.setUsername(postgresUser);
config.setPassword(postgresPassword);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
try (var ds = new HikariDataSource(config)) {
var serverDBService = new ServerDBService(ds);

View file

@ -10,6 +10,9 @@ import io.javalin.http.staticfiles.Location;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static io.javalin.apibuilder.ApiBuilder.crud;
import static io.javalin.apibuilder.ApiBuilder.path;
@ -38,9 +41,12 @@ public class WebAPI implements Runnable {
staticFileConfig.directory = "ui";
});
});
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
var waitForShutdown = new CompletableFuture<Void>();
Runtime.getRuntime().addShutdownHook(Thread.ofVirtual().name("javalin-shutdown").unstarted(() -> {
logger.info("Shutting down web application");
app.stop();
waitForShutdown.complete(null);
}));
app.events(event -> {
event.serverStopping(() -> logger.info("Stopping web service"));
@ -69,5 +75,10 @@ public class WebAPI implements Runnable {
});
app.start(this.port);
try {
waitForShutdown.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
}