aboutsummaryrefslogtreecommitdiffstats
path: root/config-proxy/src/main/sh/vespa-config-ctl.sh
blob: 1f25c792b8046ee419032dd9db3c27306f88e87c (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
#!/bin/bash
# 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; }

P_SENTINEL=var/run/sentinel.pid
P_CONFIG_PROXY=var/run/configproxy.pid

export P_SENTINEL P_CONFIG_PROXY

LOGDIR="${VESPA_HOME}/logs/vespa"
LOGFILE="$LOGDIR/vespa.log"
VESPA_LOG_TARGET="file:$LOGFILE"
VESPA_LOG_CONTROL_DIR="${VESPA_HOME}/var/db/vespa/logcontrol"
cp="lib/jars/config-proxy-jar-with-dependencies.jar"

VESPA_LOG_LEVEL="all -debug -spam"

export VESPA_LOG_TARGET VESPA_LOG_LEVEL VESPA_LOG_CONTROL_DIR

mkdir -p "$LOGDIR"
mkdir -p "$VESPA_LOG_CONTROL_DIR"

hname=$(vespa-print-default hostname)

SENTINEL_CONFIG_ID="hosts/$hname/sentinel"
export SENTINEL_CONFIG_ID
export MALLOC_ARENA_MAX=1 #Does not need fast allocation
export LD_LIBRARY_PATH="${VESPA_HOME}/lib64"


case $1 in
    start)
        nohup nice sbin/vespa-retention-enforcer > ${LOGDIR}/vre-start.log 2>&1 </dev/null &
        configsources=`bin/vespa-print-default configservers_rpc`
        userargs=$VESPA_CONFIGPROXY_JVMARGS
        heap_min=$(get_min_heap_mb "${userargs}" 32)
        heap_max=$(get_max_heap_mb "${userargs}" 128)
        jvmopts="-Xms${heap_min}M -Xmx${heap_max}M -XX:+PreserveFramePointer $(get_jvm_hugepage_settings $heap_max) -XX:CompressedClassSpaceSize=32m -XX:MaxDirectMemorySize=32m -XX:ThreadStackSize=448 -XX:MaxJavaStackTraceDepth=1000 -XX:-OmitStackTraceInFastThrow"

        VESPA_SERVICE_NAME=configproxy
        export VESPA_SERVICE_NAME
        start_seconds=$SECONDS
        echo "Starting config proxy using $configsources as config source(s)"
        vespa-runserver -r 10 -s configproxy -p $P_CONFIG_PROXY -- \
            java ${jvmopts} \
                -XX:+ExitOnOutOfMemoryError $(getJavaOptionsIPV46) \
                -Dproxyconfigsources="${configsources}" \
                -Djava.io.tmpdir=${VESPA_HOME}/var/tmp \
                ${userargs} \
                -XX:ActiveProcessorCount=2 \
                -cp $cp com.yahoo.vespa.config.proxy.ProxyServer 19090

        echo "Waiting for config proxy to start"
        fail=true
        for ((sleepcount=0;$sleepcount<1800;sleepcount=$sleepcount+1)) ; do
            sleep 0.1
            if [ -f $P_CONFIG_PROXY ] && kill -0 `cat $P_CONFIG_PROXY` && vespa-ping-configproxy -s $hname 2>/dev/null
            then
                startup_seconds=$(( SECONDS - start_seconds ))
                echo "config proxy started after ${startup_seconds}s (runserver pid `cat $P_CONFIG_PROXY`)"
                fail=false
                break
            fi
        done
        if $fail ; then
            startup_seconds=$(( SECONDS - start_seconds ))
            echo "Config proxy failed to start in ${startup_seconds}S!" 1>&2

            if ! [ -f $P_CONFIG_PROXY ]
            then
                echo "pid file $P_CONFIG_PROXY was not created" 1>&2
            elif ! kill -0 `cat $P_CONFIG_PROXY`
            then
                echo "config proxy process `cat $P_CONFIG_PROXY` has terminated" 1>&2
            elif ! vespa-ping-configproxy -s $hname
            then
                echo "failed to ping config proxy $hname" 1>&2
                kill -3 `pgrep -f -n configproxy`
            fi

            echo "look for reason in vespa.log, last part follows..." 1>&2
            tail -n 15 $LOGFILE | vespa-logfmt -  1>&2
            exit 1
        fi

        VESPA_SERVICE_NAME=config-sentinel
        export VESPA_SERVICE_NAME

        vespa-runserver -s config-sentinel -r 10 -p $P_SENTINEL -- \
            sbin/vespa-config-sentinel -c "$SENTINEL_CONFIG_ID"
        ;;

    stop)
        vespa-runserver -s config-sentinel -p $P_SENTINEL -S
        vespa-runserver -s configproxy     -p $P_CONFIG_PROXY -S
        ;;

    *)
        echo "Unknown option $@" 1>&2
        exit 1
        ;;
esac