diff options
author | Håkon Hallingstad <hakon@oath.com> | 2017-12-04 01:53:13 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@oath.com> | 2017-12-04 01:53:13 +0100 |
commit | 6842226338027546f77fb46d4d738d101bab9e07 (patch) | |
tree | 673ce1efdae0f2570733cdc8cc45f98be7f6efa7 /standalone-container/src | |
parent | 7635f081e3ef57797de662b77206e64236960e68 (diff) |
Support making standalone container and node admin RPMs
Diffstat (limited to 'standalone-container/src')
-rwxr-xr-x | standalone-container/src/main/sh/jdisc-container | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/standalone-container/src/main/sh/jdisc-container b/standalone-container/src/main/sh/jdisc-container new file mode 100755 index 00000000000..5d023e5de4d --- /dev/null +++ b/standalone-container/src/main/sh/jdisc-container @@ -0,0 +1,218 @@ +#!/bin/bash +# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +# BEGIN environment bootstrap section +# Do not edit between here and END as this section should stay identical in all scripts + +findpath () { + myname=${0} + mypath=${myname%/*} + myname=${myname##*/} + if [ "$mypath" ] && [ -d "$mypath" ]; then + return + fi + mypath=$(pwd) + if [ -f "${mypath}/${myname}" ]; then + return + fi + echo "FATAL: Could not figure out the path where $myname lives from $0" + exit 1 +} + +COMMON_ENV=libexec/vespa/common-env.sh + +source_common_env () { + if [ "$VESPA_HOME" ] && [ -d "$VESPA_HOME" ]; then + export VESPA_HOME + common_env=$VESPA_HOME/$COMMON_ENV + if [ -f "$common_env" ]; then + . $common_env + return + fi + fi + return 1 +} + +findroot () { + source_common_env && return + if [ "$VESPA_HOME" ]; then + echo "FATAL: bad VESPA_HOME value '$VESPA_HOME'" + exit 1 + fi + if [ "$ROOT" ] && [ -d "$ROOT" ]; then + VESPA_HOME="$ROOT" + source_common_env && return + fi + findpath + while [ "$mypath" ]; do + VESPA_HOME=${mypath} + source_common_env && return + mypath=${mypath%/*} + done + echo "FATAL: missing VESPA_HOME environment variable" + echo "Could not locate $COMMON_ENV anywhere" + exit 1 +} + +findroot + +# END environment bootstrap section + +Usage() { + cat <<EOF +Usage: ${0##*/} start [OPTION]... +Usage: ${0##*/} stop [OPTION]... +Manage Vespa standalone jdisc container service. + +Options: + -u USER Run as USER. Overrides any VESPA_USER environment variable. + -s SERVICE The service name. +EOF + + exit 1 +} + +Fail() { + printf "%s\n" "$*" + exit 1 +} + +FixDataDirectory() { + if ! [ -d "$1" ]; then + echo "Creating data directory '$1'" + mkdir -p "$1" || exit 1 + fi + chown "${VESPA_USER}" "$1" + chmod 755 "$1" +} + +StartCommand() { + local service="$1" + shift + + if (( $# > 0 )); then + Fail "Too many arguments" + fi + + # common setup + export VESPA_SERVICE_NAME="$service" + + # stuff for the process: + local appdir="$VESPA_HOME/conf/$service-app" + local pidfile="$VESPA_HOME/var/run/$service.pid" + local cfpfile="$VESPA_HOME/var/jdisc_core/$service.properties" + local bundlecachedir="$VESPA_HOME/var/vespa/bundlecache/$service" + + cd "$VESPA_HOME" || Fail "Cannot cd to $VESPA_HOME" + + fixlimits + checkjava + + local vespa_log="$VESPA_HOME/logs/vespa/vespa.log" + export VESPA_LOG_TARGET="file:$vespa_log" + mkdir -p "$(dirname "$vespa_log")" + + export VESPA_LOG_CONTROL_FILE="$VESPA_HOME/var/db/vespa/logcontrol/$service.logcontrol" + export VESPA_LOG_CONTROL_DIR="$(dirname "$VESPA_LOG_CONTROL_FILE")" + mkdir -p "$VESPA_LOG_CONTROL_DIR" + + # Does not need fast allocation + export MALLOC_ARENA_MAX=1 + + # will be picked up by standalone-container: + export standalone_jdisc_container__app_location="$appdir" + + # class path + CP="$VESPA_HOME/lib/jars/jdisc_core-jar-with-dependencies.jar" + + mkdir -p "$(dirname "$cfpfile")" + printenv > "$cfpfile" + FixDataDirectory "$bundlecachedir" + + java \ + -Xms128m -Xmx2048m \ + -XX:+PreserveFramePointer \ + -XX:+HeapDumpOnOutOfMemoryError \ + -XX:HeapDumpPath="$VESPA_HOME/var/crash" \ + -XX:OnOutOfMemoryError="kill -9 %p" \ + -Djava.library.path="$VESPA_HOME/lib64" \ + -Djava.awt.headless=true \ + -Dsun.rmi.dgc.client.gcInterval=3600000 \ + -Dsun.net.client.defaultConnectTimeout=5000 \ + -Dsun.net.client.defaultReadTimeout=60000 \ + -Djavax.net.ssl.keyStoreType=JKS \ + -Djdisc.config.file="$cfpfile" \ + -Djdisc.export.packages= \ + -Djdisc.cache.path="$bundlecachedir" \ + -Djdisc.debug.resources=false \ + -Djdisc.bundle.path="$VESPA_HOME/lib/jars" \ + -Djdisc.logger.enabled=true \ + -Djdisc.logger.level=ALL \ + -Djdisc.logger.tag="jdisc/$service" \ + -Dfile.encoding=UTF-8 \ + -cp "$CP" \ + com.yahoo.jdisc.core.StandaloneMain standalone-container-jar-with-dependencies.jar +} + +StopCommand() { + local service="$1" + shift + + if (( $# > 0 )); then + Fail "Too many arguments" + fi + + Fail "Not implemented" +} + +Main() { + if (( $# == 0 )); then + Usage + fi + + local command="$1" + shift + + local service="standalone/container" + local user="$VESPA_USER" + + while (( $# > 0 )); do + case "$1" in + --help|-h) Usage ;; + --service|-s) + service="$2" + shift 2 + ;; + --user|-u) + user="$2" + shift 2 + ;; + *) break ;; + esac + done + + # Service name will be included in paths and possibly environment variable + # names, so be restrictive. + local service_regex='^[a-zA-Z0-9_-]+$' + if test -z "$service"; then + Fail "SERVICE not specified" + elif ! [[ "$service" =~ $service_regex ]]; then + Fail "Service must math the regex '$service_regex'" + fi + + if ! getent passwd "$user" &> /dev/null; then + Fail "Bad user ($user): not found in passwd" + elif test "$(id -un)" != "$user"; then + Fail "${0##*/} must be started by $user" + fi + export VESPA_USER="$user" + + case "$command" in + help) Usage ;; + start) StartCommand "$service" "$@" ;; + stop) StopCommand "$service" "$@" ;; + *) Fail "Unknown command '$command'" ;; + esac +} + +Main "$@" |