From d251b38291b687d925d32facc000ca4916ff4afa Mon Sep 17 00:00:00 2001 From: Override-6 Date: Sun, 4 Dec 2022 05:59:17 +0100 Subject: [PATCH] bugfixes --- drone/deploy.sh | 19 ++++++++++++------- src/main/resources/server.properties | 2 +- .../scala/org/tbasket/EndpointSetup.scala | 8 ++++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drone/deploy.sh b/drone/deploy.sh index 52c3b27..34bd49f 100644 --- a/drone/deploy.sh +++ b/drone/deploy.sh @@ -4,18 +4,23 @@ DIR=$(readlink -e "$(dirname "$0")") PROD_SERVER_JAR_NAME="server-prod.jar" NEW_SERVER_JAR_NAME="server-all.jar" -OLD_PID=$(ps -aux | tr -s " " | grep -E "\bjava -jar $PROD_SERVER_JAR_NAME\b" | cut -d " " -f2) -#if $OLD_PID is not empty but isn't a number, something went wrong -if [ "$OLD_PID" ] && ! echo "$OLD_PID" | grep -E -q "^[0-9]+$"; then - echo "error, unable to retrieve old server pid: $OLD_PID" >&2 +prod_pid() { + ps -aux | tr -s " " | grep -E "\bjava -jar $PROD_SERVER_JAR_NAME\b" | cut -d " " -f2 +} + +PROD_PID=$(prod_pid) + +#if $PROD_PID is not empty but isn't a number, something went wrong +if [ "$PROD_PID" ] && ! echo "$PROD_PID" | grep -E -q "^[0-9]+$"; then + echo "error, unable to retrieve old server pid: $PROD_PID" >&2 exit 2 fi -if [ "$OLD_PID" ]; then +if [ "$PROD_PID" ]; then #will cause the old server to gracefully shutdown echo "shutting down old server version ..." - kill -s SIGQUIT "$OLD_PID" - while ! kill -s 0 "$OLD_PID"; do sleep 1; done #sleep until process ends + kill -s SIGQUIT "$PROD_PID" + while [ ! "$(prod_pid)" ]; do sleep 1; done #sleep until process ends fi rm "$DIR/$PROD_SERVER_JAR_NAME" diff --git a/src/main/resources/server.properties b/src/main/resources/server.properties index 52a2da6..aea62c7 100644 --- a/src/main/resources/server.properties +++ b/src/main/resources/server.properties @@ -1 +1 @@ -endpoint.url=48485 \ No newline at end of file +endpoint.port=48485 \ No newline at end of file diff --git a/src/main/scala/org/tbasket/EndpointSetup.scala b/src/main/scala/org/tbasket/EndpointSetup.scala index 78ce397..bda306e 100644 --- a/src/main/scala/org/tbasket/EndpointSetup.scala +++ b/src/main/scala/org/tbasket/EndpointSetup.scala @@ -7,8 +7,8 @@ import java.util.Properties object EndpointSetup { - final val EndpointUrl = "endpoint.url" - final val EndpointUrlDefault = s"localhost:48485" + final val EndpointPort = "endpoint.port" + final val EndpointPortDefault = "48485" def setupEndpoint(config: Properties): Endpoint = { Main.LOG.debug("Initializing API endpoint...") @@ -19,10 +19,10 @@ object EndpointSetup { private def createEndpoint(config: Properties): Endpoint = { val port = config - .getProperty(EndpointUrl, EndpointUrlDefault) match { + .getProperty(EndpointPort, EndpointPortDefault) match { case s"$port" if port.toIntOption.isDefined => port.toInt case v => - throw new InternalBasketServerException(s"$EndpointUrl property value is wrong: $v must be integer") + throw new InternalBasketServerException(s"$EndpointPort property value is wrong: $v must be integer") } new Endpoint(port) }