Skip to content

Commit

Permalink
Remove commons-daemon from dependencies
Browse files Browse the repository at this point in the history
Motivation:
The current version of `jsvc` does not support Java 9+.
If we can remove `commons-daemon` from dependencies, we would have less blocker for supporting latest Java version.

Modifications:
- Removed `commons-daemon` from dependencies.
- Removed `jsvc` binaries from `dist/src/bin`.
- The server now creates a pidfile when it starts up and deletes it when it is terminated.
  - `startup`/`shutdown` waits until the pidfile is created/deleted.
- Updated `Dockerfile`:
  - Using `openjdk:lastest` instead of `openjdk:8`.
  - Set the entry point in order to correctly handle a signal from a user.
    `docker stop` command, which sends `TERM` signal to the container, will work.

Result:
- Less dependencies.
- Support Java 9+.
  • Loading branch information
hyangtack committed Feb 28, 2019
1 parent 066d02e commit ddaeae3
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 170 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
Expand Up @@ -6,8 +6,6 @@
/gradlew text eol=lf

/dist/src/bin/*.sh text eol=lf
/dist/src/bin/jsvc.* binary

/dist/src/bin/dogma text eol=lf
/dist/src/bin/startup text eol=lf
/dist/src/bin/shutdown text eol=lf
10 changes: 5 additions & 5 deletions NOTICE.txt
Expand Up @@ -165,11 +165,6 @@ This product depends on Caffeine, distributed by Ben Manes:
* License: licenses/LICENSE.caffeine.al20.txt (Apache License v2.0)
* Homepage: https://github.com/ben-manes/caffeine

This product depends on Commons Daemon, distributed by Apache Software Foundation:

* License: licenses/LICENSE.commons-daemon.al20.txt (Apache License v2.0)
* Homepage: https://commons.apache.org/proper/commons-daemon/

This product depends on completable-futures, distributed by Spotify AB:

* License: license/LICENSE.completable-futures.al20.txt (Apache License v2.0)
Expand Down Expand Up @@ -255,6 +250,11 @@ This product depends on jGit, distributed by Eclipse Foundation:
* License: licenses/LICENSE.jgit.edl10.txt (Eclipse Distribution License v1.0)
* Homepage: https://eclipse.org/jgit/

This product depends on jnr-ffi, distributed by jnr contributors:

* License: licenses/LICENSE.jnr-ffi.al20.txt (Apache License v2.0)
* Homepage: https://github.com/jnr/jnr-ffi

This product depends on JSch, distributed by JCraft, Inc:

* License: licenses/LICENSE.jsch.bsd.txt (New BSD License)
Expand Down
12 changes: 3 additions & 9 deletions dependencies.yml
Expand Up @@ -48,9 +48,6 @@ com.fasterxml.jackson.datatype:
jackson-datatype-jsr310:
version: *JACKSON_VERSION

com.fasterxml.jackson.datatype:
jackson-datatype-jsr310: { version: '2.9.8' }

# TODO(trustin): Relocate Caffeine after hiding CacheStats from the public API.
com.github.ben-manes.caffeine:
caffeine:
Expand All @@ -61,6 +58,9 @@ com.github.ben-manes.caffeine:
com.github.jengelman.gradle.plugins:
shadow: { version: '4.0.4' }

com.github.jnr:
jnr-ffi: { version: '2.1.9' }

com.google.code.findbugs:
jsr305: { version: '3.0.2' }

Expand Down Expand Up @@ -123,12 +123,6 @@ com.spotify:
- from: com.spotify.futures
to: com.linecorp.centraldogma.internal.shaded.futures

commons-daemon:
commons-daemon:
version: '1.0.15'
javadocs:
- https://commons.apache.org/proper/commons-daemon/apidocs/

gradle.plugin.com.github.blindpirate:
gogradle: { version: '0.11.3' }

Expand Down
7 changes: 4 additions & 3 deletions dist/Dockerfile
@@ -1,11 +1,11 @@
#
# CentralDogma Dockerfile
#
FROM openjdk:8
FROM openjdk:latest

# Environment variables.
ENV CENTRALDOGMA_HOME "/opt/centraldogma"
ENV CENTRALDOGMA_OPTS "-nodetach"
ENV CENTRALDOGMA_OPTS ""
ENV JAVA_OPTS "$CENTRALDOGMA_OPTS"
ENV PATH "$CENTRALDOGMA_HOME/bin:$PATH"

Expand All @@ -30,4 +30,5 @@ COPY build/dist/licenses/* "$CENTRALDOGMA_HOME"/licenses/
# Expose ports.
EXPOSE 36462

CMD ["sh", "-c", "${CENTRALDOGMA_HOME}/bin/startup"]
# Entrypoint doesn't allow an environment variable.
ENTRYPOINT ["/opt/centraldogma/bin/startup", "-nodetach"]
43 changes: 14 additions & 29 deletions dist/src/bin/common.sh
@@ -1,4 +1,4 @@
# Common script for JSVC-based Java application
# Common script for Java application
#
# This script checks if the following environment variables exist and sets their default values if necessary.
# -----------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -26,13 +26,13 @@
# APP_STDERR_FILE (Optional) The path to the file that contains the stderr console output
# If not set, '$APP_LOG_DIR/$APP_NAME.stderr' is used.
#
# APP_WAIT_TIME (Optional) Wait the specified seconds for the service to start or stop.
# If not set, 60 seconds are used.
#
# JAVA_HOME (Required) The location of the installed JDK/JRE
#
# JAVA_OPTS (Optional) The JVM options
#
# JSVC_BIN (Optional) The patch to the JSVC executable.
# If not set, '$APP_HOME/bin/jsvc.<auto-detected-os-classifier>' is used.
#

set -e

Expand Down Expand Up @@ -88,30 +88,15 @@ if [[ -z "$APP_STDERR_FILE" ]]; then
APP_STDERR_FILE="$APP_LOG_DIR/$APP_NAME".stderr
fi

if [[ -z "$APP_PID_FILE" ]]; then
APP_PID_FILE="$APP_HOME/$APP_NAME".pid
fi

JSVC_AUTODETECT=1
if [[ -n "$JSVC_BIN" ]]; then
if [[ ! -x "$JSVC_BIN" ]]; then
eecho "$JSVC_BIN is not an executable; falling back to auto-detection."
else
JSVC_AUTODETECT=0
fi
fi

if [[ $JSVC_AUTODETECT -ne 0 ]]; then
case "`uname`" in
Darwin) JSVC_BIN="$APP_BIN_DIR/jsvc.osx" ;;
Linux) JSVC_BIN="$APP_BIN_DIR/jsvc.linux-`uname -m`" ;;
*) JSVC_BIN="$APP_BIN_DIR/jsvc.unknown" ;;
esac
if [[ -z "$APP_WAIT_TIME" ]]; then
APP_WAIT_TIME=60
elif [[ ! "$APP_WAIT_TIME" =~ (^[0-9]+$) ]]; then
eecho "Invalid APP_WAIT_TIME: $APP_WAIT_TIME"
exit 5
fi

if [[ ! -x ${JSVC_BIN} ]]; then
eecho "Could not find the suitable JSVC executable. Set the JSVC environment variable to override auto-detection."
exit 5
if [[ -z "$APP_PID_FILE" ]]; then
APP_PID_FILE="$APP_HOME/$APP_NAME".pid
fi

if [[ -f "$(dirname "$0")/common.post.sh" ]]; then
Expand All @@ -128,9 +113,9 @@ export APP_BIN_DIR \
APP_PID_FILE \
APP_STDOUT_FILE \
APP_STDERR_FILE \
APP_WAIT_TIME \
JAVA_HOME \
JAVA_OPTS \
JSVC_BIN
JAVA_OPTS

eecho "Environment variables:"
eecho "======================"
Expand All @@ -144,7 +129,7 @@ eecho "APP_OPTS: $APP_OPTS"
eecho "APP_PID_FILE: $APP_PID_FILE"
eecho "APP_STDOUT_FILE: $APP_STDOUT_FILE"
eecho "APP_STDERR_FILE: $APP_STDERR_FILE"
eecho "APP_WAIT_TIME: $APP_WAIT_TIME"
eecho "JAVA_HOME: $JAVA_HOME"
eecho "JAVA_OPTS: $JAVA_OPTS"
eecho "JSVC_BIN: $JSVC_BIN"
eecho
Binary file removed dist/src/bin/jsvc.linux-x86_64
Binary file not shown.
Binary file removed dist/src/bin/jsvc.osx
Binary file not shown.
38 changes: 16 additions & 22 deletions dist/src/bin/shutdown
Expand Up @@ -10,38 +10,32 @@ if [[ -f "$APP_PID_FILE" ]]; then
if [[ $? -gt 0 ]]; then
eecho "PID file exists, but its process ($PID) does not exist; removing $APP_PID_FILE"
rm -f "$APP_PID_FILE" > /dev/null 2>&1
exit 10
exit 100
fi
else
eecho "$APP_PID_FILE does not contain a PID."
exit 10
exit 100
fi
else
eecho "PID file does not exist; $APP_NAME not running?"
exit 10
exit 100
fi

# Shut the application down with JSVC
# Shut the application down
set +e
eecho "Shutting down $APP_NAME ($(cat "$APP_PID_FILE")) .."

"$JSVC_BIN" \
-stop \
-java-home "$JAVA_HOME" \
-pidfile "$APP_PID_FILE" \
-cwd "$APP_HOME" \
-outfile "$APP_STDOUT_FILE" \
-errfile "$APP_STDERR_FILE" \
-classpath "$APP_HOME/conf:$APP_LIB_DIR/ext/*:$APP_LIB_DIR/*" \
"$APP_MAIN"
kill -TERM $PID

JSVC_EXIT_CODE=$?

if [[ "$JSVC_EXIT_CODE" -ne 0 ]]; then
eecho "Failed to shut down $APP_NAME (exit code: $JSVC_EXIT_CODE)"
exit $JSVC_EXIT_CODE
else
eecho "Shut down $APP_NAME successfully."
exit 0
fi
COUNT=0
while [[ $APP_WAIT_TIME -eq 0 ]] || [[ $COUNT -lt $APP_WAIT_TIME ]]; do
sleep 1
if [[ ! -f "$APP_PID_FILE" ]]; then
eecho "Shut down $APP_NAME successfully."
exit 0
fi
COUNT=`expr $COUNT + 1`
done

eecho "Failed to shut down $APP_NAME"
exit 255
68 changes: 49 additions & 19 deletions dist/src/bin/startup
Expand Up @@ -3,43 +3,73 @@
source "$(dirname "$0")/common.sh"
cd "$APP_HOME"

NODETACH=0

while [[ $# -gt 0 ]]
do
case "$1" in
-nodetach)
NODETACH=1
;;
*)
eecho "Unknown argument: $1"
eecho "Usage: `basename $0` [-nodetach]"
exit 10
;;
esac
shift
done

if [[ -f "$APP_PID_FILE" ]]; then
PID="`cat "$APP_PID_FILE"`"
if [[ ! "$PID" =~ (^[0-9]+$) ]]; then
eecho "PID file exists, but it does not contain a PID; removing $APP_PID_FILE"
fi
if ps -p "$PID" >/dev/null 2>&1; then
eecho "$APP_NAME started already with PID $PID; aborting."
exit 10
exit 100
else
eecho "PID file exists, but its process ($PID) does not exist; removing $APP_PID_FILE"
fi
fi

rm -f "$APP_PID_FILE" >/dev/null 2>&1

# Start the application up with jsvc
mkdir -p `dirname $APP_STDOUT_FILE`
mkdir -p `dirname $APP_STDERR_FILE`

# Start the application up
set +e
eecho "Starting up $APP_NAME .."
"$JSVC_BIN" \
-java-home "$JAVA_HOME" \
-pidfile "$APP_PID_FILE" \
-wait 60 \
-cwd "$APP_HOME" \
-outfile "$APP_STDOUT_FILE" \
-errfile "$APP_STDERR_FILE" \

nohup "$JAVA_HOME"/bin/java \
${JAVA_OPTS} \
-classpath "$APP_HOME/conf:$APP_LIB_DIR/ext/*:$APP_LIB_DIR/*" \
"$APP_MAIN" \
$APP_OPTS

JSVC_EXIT_CODE=$?
-pidfile "$APP_PID_FILE" \
$APP_OPTS \
1> "$APP_STDOUT_FILE" \
2> "$APP_STDERR_FILE" \
&

if [[ "$JSVC_EXIT_CODE" -ne 0 ]]; then
eecho "Failed to start up $APP_NAME (exit code: $JSVC_EXIT_CODE)"
exit $JSVC_EXIT_CODE
else
eecho "Started up $APP_NAME successfully: $(cat "$APP_PID_FILE")"
exit 0
fi
COUNT=0
while [[ $APP_WAIT_TIME -eq 0 ]] || [[ $COUNT -lt $APP_WAIT_TIME ]]; do
sleep 1
if [[ -f "$APP_PID_FILE" ]]; then
PID=$(cat "$APP_PID_FILE")
kill -0 $PID > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
eecho "Started up $APP_NAME successfully: $PID"
if [[ $NODETACH -eq 1 ]]; then
trap "$APP_BIN_DIR/shutdown" SIGINT SIGTERM SIGKILL SIGHUP
wait $PID
fi
exit 0
fi
break
fi
COUNT=`expr $COUNT + 1`
done

eecho "Failed to start up $APP_NAME"
exit 255

0 comments on commit ddaeae3

Please sign in to comment.