aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/sh/start-configserver
blob: 81e96c19f12ea30462a999e3e62a668522108bb3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/sh
# Copyright Vespa.ai. 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##*/}
    empty_if_start_slash=${mypath%%/*}
    if [ "${empty_if_start_slash}" ]; then
        mypath=$(pwd)/${mypath}
    fi
    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
}

findhost () {
    if [ "${VESPA_HOSTNAME}" = "" ]; then
        VESPA_HOSTNAME=$(vespa-detect-hostname || hostname -f || hostname || echo "localhost") || exit 1
    fi
    validate="${VESPA_HOME}/bin/vespa-validate-hostname"
    if [ -f "$validate" ]; then
        "$validate" "${VESPA_HOSTNAME}" || exit 1
    fi
    export VESPA_HOSTNAME
}

findroot
findhost

ROOT=${VESPA_HOME%/}
export ROOT

# END environment bootstrap section

cd ${VESPA_HOME} || { echo "Cannot cd to ${VESPA_HOME}" 1>&2; exit 1; }

fixfile () {
    if [ -f $1 ]; then
        if [ "${VESPA_USER}" ] && [ "$(id -u)" -eq 0 ]; then
            chown ${VESPA_USER} $1
        fi
        chmod 644 $1
    fi
}

fixddir () {
    if ! [ -d $1 ]; then
       echo "Creating data directory $1"
       mkdir -p $1 || exit 1
    fi
    if [ "${VESPA_USER}" ] && [ "$(id -u)" -eq 0 ]; then
        chown ${VESPA_USER} $1
    fi
    chmod 755 $1
}

fixddir ${VESPA_HOME}/var/zookeeper
fixddir ${VESPA_HOME}/var/zookeeper/conf
fixfile ${VESPA_HOME}/var/zookeeper/conf/zookeeper.cfg
fixfile ${VESPA_HOME}/var/zookeeper/myid
fixddir ${VESPA_HOME}/var/zookeeper/version-2

not_a_configserver () {
    for hn in $(vespa-print-default configservers); do
        if [ "$hn" = localhost ] || [ "$hn" = "${VESPA_HOSTNAME}" ]; then
            return 1
        fi
    done
    return 0
}

if not_a_configserver ; then
    echo "Will not start config server, host ${VESPA_HOSTNAME}" \
         "is not part of VESPA_CONFIGSERVERS: " $(vespa-print-default configservers)
    exit 1
fi

fixlimits
checkjava

ZOOKEEPER_LOG_FILE_PREFIX="${VESPA_HOME}/logs/vespa/zookeeper.configserver"
rm -f ZOOKEEPER_LOG_FILE_PREFIX*lck

# common setup
export VESPA_LOG_TARGET=file:${VESPA_HOME}/logs/vespa/vespa.log
export VESPA_LOG_CONTROL_DIR="${VESPA_HOME}/var/db/vespa/logcontrol"
export VESPA_LOG_CONTROL_FILE="${VESPA_HOME}/var/db/vespa/logcontrol/configserver.logcontrol"
export VESPA_SERVICE_NAME=configserver
export LD_LIBRARY_PATH=${VESPA_HOME}/lib64

# Does not need fast allocation
export MALLOC_ARENA_MAX=1

vespa-run-as-vespa-user ${VESPA_HOME}/libexec/vespa/start-logd

# stuff for the configserver process:

appdir="${VESPA_HOME}/conf/configserver-app"
pidfile="${VESPA_HOME}/var/run/configserver.pid"
cfpfile="${VESPA_HOME}/var/jdisc_container/configserver.properties"
bundlecachedir="${VESPA_HOME}/var/vespa/bundlecache/configserver"

export JAVAVM_LD_PRELOAD=
unset LD_PRELOAD
# will be picked up by standalone-container:
export standalone_jdisc_container__app_location=${appdir}
export standalone_jdisc_container__deployment_profile=configserver

# class path
CP="${VESPA_HOME}/lib/jars/jdisc_core-jar-with-dependencies.jar"

jvmoptions="$VESPA_CONFIGSERVER_JVMARGS"

export LD_PRELOAD=${VESPA_HOME}/lib64/vespa/malloc/libvespamalloc.so

rm -f $cfpfile
vespa-run-as-vespa-user sh -c "printenv > $cfpfile"
fixddir $bundlecachedir

heap_min=$(get_min_heap_mb "${jvmoptions}" 128)
heap_max=$(get_max_heap_mb "${jvmoptions}" 2048)
vespa-run-as-vespa-user vespa-runserver -s ${VESPA_SERVICE_NAME} -r 30 -p $pidfile -- \
	java \
	-Xms${heap_min}m -Xmx${heap_max}m \
        $(get_jvm_hugepage_settings $heap_max) \
	-XX:+PreserveFramePointer \
	-XX:+HeapDumpOnOutOfMemoryError \
	-XX:HeapDumpPath="${VESPA_HOME}/var/crash" \
	-XX:ErrorFile="${VESPA_HOME}/var/crash/hs_err_pid%p.log" \
	-XX:+ExitOnOutOfMemoryError \
	-XX:-OmitStackTraceInFastThrow \
	-XX:MaxJavaStackTraceDepth=1000000 \
	$jvmoptions \
        --add-opens=java.base/java.io=ALL-UNNAMED \
        --add-opens=java.base/java.lang=ALL-UNNAMED \
        --add-opens=java.base/java.net=ALL-UNNAMED \
        --add-opens=java.base/java.nio=ALL-UNNAMED \
        --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED \
        --add-opens=java.base/sun.security.ssl=ALL-UNNAMED  \
	-Djava.io.tmpdir=${VESPA_HOME}/var/tmp \
	-Djava.library.path=${VESPA_HOME}/lib64 \
	-Djava.security.properties=${VESPA_HOME}/conf/vespa/java.security.override \
	-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 \
	-Djdk.tls.rejectClientInitiatedRenegotiation=true \
	-Djdisc.config.file=$cfpfile \
	-Djdisc.export.packages= \
	-Djdisc.cache.path=$bundlecachedir \
	-Djdisc.bundle.path=${VESPA_HOME}/lib/jars \
	-Djdisc.logger.enabled=false \
	-Djdisc.logger.level=WARNING \
	-Djdisc.logger.tag=${VESPA_SERVICE_NAME} \
	-Dfile.encoding=UTF-8 \
	-Dzookeeper_log_file_prefix=${ZOOKEEPER_LOG_FILE_PREFIX} \
	-cp "$CP" \
	com.yahoo.jdisc.core.StandaloneMain standalone-container-jar-with-dependencies.jar