diff --git a/Docker/_README.md b/Docker/_README.md index b79be602fc..b5ee4e64ce 100644 --- a/Docker/_README.md +++ b/Docker/_README.md @@ -275,6 +275,11 @@ The shell script `$SCRIPT_DIR/run.sh` has commands, that are used for operating ```bash bash /run.sh -q auto-restart ``` +The command used for initiating 'auto-restart' for the prod server and looking up the pid (if not found in the log-file) are: +```bash +/bin/bash /data/openroberta-lab/scripts/run.sh -q auto-restart master http://me-roblab-prod:8080 +ps -AfL | fgrep auto-restart +``` * `alive`: usually called from cron. It takes a server URL and checks whether the server is alive. It sends by default mail to admins. Use `crontab -e` to add the following line to the crontab. call /run.sh -help to learn about other parameters of the call: @@ -296,7 +301,7 @@ bash /run.sh -q auto-restart # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: openrobertalab service -# Description: Start, stop and restart the database server and the openroberta server declared in server/servers.txt +# Description: Start, stop and restart the database server and the openroberta server ### END INIT INFO # Author: rbudde diff --git a/Docker/openroberta/scripts/hotfix.sh b/Docker/openroberta/scripts/hotfix.sh index 4a3f4734b6..5e022d64fd 100755 --- a/Docker/openroberta/scripts/hotfix.sh +++ b/Docker/openroberta/scripts/hotfix.sh @@ -6,7 +6,7 @@ echo ' # For deployments, two parameters are mandatory (both WITHOUT SNAPSHOT) # # 1. the version number of the hotfix to be deployed at master (likely the version from develop without -SNAPSHOT) # # 2. the next version to be set in develop (the script suffixes this with "-SNAPSHOT" internally) # -# E.g. ./hotfix.sh 2.4.1 2.5.0 # +# E.g. ./hotfix.sh 4.0.2 4.0.3 # # # # ASSUMPTIONS: # # - maven project, may be hierarchical (parent + modules). mvn is used and on the PATH! # diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/provider/RuntimeExceptionMapper.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/provider/RuntimeExceptionMapper.java index 2a309f8a69..f68706c6aa 100644 --- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/provider/RuntimeExceptionMapper.java +++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/provider/RuntimeExceptionMapper.java @@ -23,7 +23,9 @@ public class RuntimeExceptionMapper implements ExceptionMapper @Override public Response toResponse(RuntimeException e) { try { - LOG.error("server error - exception: " + e.getMessage().substring(0, 60), e); + String errorMessage = e.getMessage(); + errorMessage = (errorMessage == null) ? "-no error message in exception-" : errorMessage.substring(0, 60); + LOG.error("server error - exception: " + errorMessage, e); final BaseResponse response = BaseResponse.make(); String keyAsString = Key.SERVER_ERROR.toString(); response.setRc("error").setMessage(keyAsString).setCause(keyAsString); diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/ServerStarter.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/ServerStarter.java index 1be95fd6f5..e55599537f 100644 --- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/ServerStarter.java +++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/ServerStarter.java @@ -72,7 +72,8 @@ public class ServerStarter { private static final String ADMIN_DIR_KEY = "server.admin.dir="; private static final String LOG_LEVEL_KEY = "server.log.level="; - private static final long INTERVAL_TO_CHECK_EXPIRATIONS_SEC = TimeUnit.HOURS.toSeconds(3); + private static final long INTERVAL_HTTPSESSION_EXPIRE_SEC = TimeUnit.HOURS.toSeconds(3); + private static final long INTERVAL_DB_SESSION_EXPIRE_SEC = TimeUnit.MINUTES.toSeconds(30); private final ServerProperties serverProperties; // for the startup private Injector injector; @@ -345,7 +346,7 @@ private IIpToCountry configureIpToCountryDb() { } /** - * configure a thread, that runs every 3 hours a service, that will remove expired HttpSessionState objects + * configure a thread, that runs periodically a service, that will remove expired HttpSessionState objects */ private void configureHttpSessionStateCleanup() { ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); @@ -355,11 +356,11 @@ public void run() { HttpSessionState.removeExpired(); } }; - scheduler.scheduleAtFixedRate(cleanupHttpSessionState, INTERVAL_TO_CHECK_EXPIRATIONS_SEC + 1, INTERVAL_TO_CHECK_EXPIRATIONS_SEC, TimeUnit.SECONDS); + scheduler.scheduleAtFixedRate(cleanupHttpSessionState, INTERVAL_HTTPSESSION_EXPIRE_SEC + 1, INTERVAL_HTTPSESSION_EXPIRE_SEC, TimeUnit.SECONDS); } /** - * configure a thread, that runs every 3 hours a service, that will remove expired database sessions (sessions older than 2 hours) + * configure a thread, that runs periodically a service, that will remove expired database sessions */ private void configureDbSessionCleanup() { ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); @@ -369,7 +370,7 @@ public void run() { DbSession.cleanupSessions(); } }; - scheduler.scheduleAtFixedRate(cleanupDbSession, INTERVAL_TO_CHECK_EXPIRATIONS_SEC + 2, INTERVAL_TO_CHECK_EXPIRATIONS_SEC, TimeUnit.SECONDS); + scheduler.scheduleAtFixedRate(cleanupDbSession, INTERVAL_DB_SESSION_EXPIRE_SEC + 2, INTERVAL_DB_SESSION_EXPIRE_SEC, TimeUnit.SECONDS); } /** diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/DbSession.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/DbSession.java index 1b786330d1..a2dbb2b12b 100644 --- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/DbSession.java +++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/DbSession.java @@ -27,9 +27,14 @@ */ public class DbSession { private static final Logger LOG = LoggerFactory.getLogger(DbSession.class); + /** + * if a db session is older than this value, it will be logged as a potential resource misuse + */ private static final long DURATION_TIMEOUT_MSEC_FOR_LOGGING = TimeUnit.SECONDS.toMillis(5); - private static final long DURATION_TIMEOUT_MSEC_FOR_CLEANUP = TimeUnit.HOURS.toMillis(2); - private static final int NUMBER_OF_SESSIONS_TO_SHOW = 50; + /** + * if a db session is older than this value, it will be closed and removed to avoid a resource leak + */ + private static final long DURATION_TIMEOUT_MSEC_FOR_CLEANUP = TimeUnit.MINUTES.toMillis(5); private Session session; @@ -68,13 +73,17 @@ public class DbSession { * rollback the current transaction */ public void rollback() { - LOG.info("rollback"); addTransaction("rollback"); // for analyzing db session usage. + if ( this.session != null ) { + LOG.info("rollback"); + Transaction transaction = this.session.getTransaction(); + transaction.rollback(); + this.session.close(); + this.session = null; + } else { + LOG.info("rollback attempt - session was removed already"); + } - Transaction transaction = this.session.getTransaction(); - transaction.rollback(); - this.session.close(); - this.session = null; } /** @@ -112,12 +121,13 @@ public void close() { if ( new Date().getTime() - creationTime > DURATION_TIMEOUT_MSEC_FOR_LOGGING ) { LOG.error("db session " + sessionId + " too old: " + sessionAge + "msec\n" + getFullInfo()); } - currentOpenSessionCounter.decrementAndGet(); if ( this.numberOfActions == 0 ) { unusedSessionCounter.getAndIncrement(); } if ( sessionMap.remove(this.sessionId) == null ) { LOG.error("FATAL: could not remove db session " + this.sessionId); + } else { + currentOpenSessionCounter.decrementAndGet(); } } @@ -224,7 +234,7 @@ private void addSaveOrDelete(String cmd, Object object) { } /** - * remove (cleanup) all those db sessions, that are outdated. This is a VERY dangerous operation! + * rollback and remove all those db sessions, that are outdated (older than {@link #DURATION_TIMEOUT_MSEC_FOR_CLEANUP}). This is a VERY dangerous operation! */ public static void cleanupSessions() { final long now = new Date().getTime(); @@ -248,7 +258,7 @@ public static void cleanupSessions() { } } if ( !somethingExpired ) { - LOG.info("no expired database session"); + LOG.info("no sessions expired"); } } diff --git a/OpenRobertaServer/src/main/resources/hibernate-cfg.xml b/OpenRobertaServer/src/main/resources/hibernate-cfg.xml index a9fcc5d671..56a96fdbcd 100644 --- a/OpenRobertaServer/src/main/resources/hibernate-cfg.xml +++ b/OpenRobertaServer/src/main/resources/hibernate-cfg.xml @@ -14,7 +14,7 @@ false 5 - 100 + 200 700 300 100