|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +DEFAULT_INFLUXDB3_HOME=/usr/local/influxb3 |
| 4 | +PROFILE="${INFLUXDB3_PROFILE:-quick-release}" |
| 5 | + |
| 6 | +INFLUXDB3_PRJ_HOME="${INFLUXDB3_PRJ_HOME:-${DEFAULT_INFLUXDB3_HOME}}" |
| 7 | +INFLUXDB3_EXE="${INFLUXDB3_PRJ_HOME}/target/${PROFILE}/influxdb3" |
| 8 | + |
| 9 | +SECURE_DEPLOY="${INFLUXDB3_SECURE_DEPLOY:-TRUE}" |
| 10 | +OBJECT_STORE="${INFLUXDB3_OBJECT_STORE:-file}" |
| 11 | +HOST_ID="${INFLUXDB3_HOST_ID:-client_test}" |
| 12 | +DATA_DIR="${INFLUXDB3_DATA_DIR:-/tmp/influxdb3/data}" |
| 13 | +PROCESS_FILE="$(pwd)/influxdb3.pid" |
| 14 | + |
| 15 | +if [ -f "${PROCESS_FILE}" ] |
| 16 | +then |
| 17 | + OLD_PROCESS=$(cat ${PROCESS_FILE}) |
| 18 | + if [ -d "/proc/${OLD_PROCESS}" ] |
| 19 | + then |
| 20 | + printf "Influxdb3 already running as process %s\n" "${OLD_PROCESS}" |
| 21 | + printf "EXITING\n" |
| 22 | + exit 0 |
| 23 | + fi |
| 24 | +fi |
| 25 | + |
| 26 | +START_DIR=$(pwd) |
| 27 | + |
| 28 | +if ! [ -d "${INFLUXDB3_PRJ_HOME}" ] |
| 29 | +then |
| 30 | + printf "Directory for INFLUXDB3_PRJ_HOME %s not found.\n" "${INFLUXDB3_PRJ_HOME}" |
| 31 | + printf "Set the environment variable INFLUXDB3_PRJ_HOME to the local project location.\n" |
| 32 | + printf "ABORTING\n" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +if ! [ -f "${INFLUXDB3_PRJ_HOME}/Cargo.toml" ] |
| 37 | +then |
| 38 | + printf "%s exists but is not a Rust/Cargo project.\n" "${INFLUXDB3_PRJ_HOME}" |
| 39 | + printf "ABORTING\n" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +if [ -x "${INFLUXDB3_EXE}" ] |
| 44 | +then |
| 45 | + printf "found %s\n" "$(ls "${INFLUXDB3_EXE}")" |
| 46 | + printf "build skipped\n" |
| 47 | + printf "\nto force rebuild run '$ cargo clean' in directory %s, then run this script again\n\n" "${INFLUXDB3_PRJ_HOME}" |
| 48 | +else |
| 49 | + START_DIR=$(pwd) |
| 50 | + echo DEBUG START_DIR "${START_DIR}" |
| 51 | + cd "${INFLUXDB3_PRJ_HOME}" || exit |
| 52 | + printf "Building Influxdb3 with profile %s\n" "${PROFILE}" |
| 53 | + printf "Building in %s" "$(pwd)\n" |
| 54 | + printf "This may take a few minutes\n" |
| 55 | + cargo build --package="influxdb3" --profile="${PROFILE}" --no-default-features --features="jemalloc_replacing_malloc" |
| 56 | + BUILD_RESULT=$? |
| 57 | + # shellcheck disable=SC2164 |
| 58 | + cd "${START_DIR}" || cd - |
| 59 | + printf "Build end status %s\n" "${BUILD_RESULT}" |
| 60 | + if [ "${BUILD_RESULT}" != 0 ] |
| 61 | + then |
| 62 | + printf "Build failed\n" |
| 63 | + printf "ABORTING\n" |
| 64 | + exit ${BUILD_RESULT} |
| 65 | + fi |
| 66 | +fi |
| 67 | + |
| 68 | +if [ ! -e "${INFLUXDB3_EXE}" ] |
| 69 | +then |
| 70 | + printf "Failed to locate influxdb3 executable %s\n" "${INFLUXDB3_EXE}" |
| 71 | + printf "ABORTING\n" |
| 72 | + exit 1 |
| 73 | +fi |
| 74 | + |
| 75 | +if [ ! -x "${INFLUXDB3_EXE}" ] |
| 76 | +then |
| 77 | + printf "Found influxdb3 file %s\n" "${INFLUXDB3_EXE}" |
| 78 | + printf "But it is not executable\n" |
| 79 | + printf "ABORTING" |
| 80 | + exit 1 |
| 81 | +fi |
| 82 | + |
| 83 | +printf "Preparing to deploy\n" |
| 84 | +DEPLOY_ARGS="--host-id ${HOST_ID} --object-store ${OBJECT_STORE} --data-dir ${DATA_DIR} --log-filter DEBUG" |
| 85 | + |
| 86 | +if [ "${SECURE_DEPLOY}" == "TRUE" ] |
| 87 | +then |
| 88 | + TOKEN_RESULT=$(${INFLUXDB3_EXE} token create | head -n 2 | sed ':a;N;$!ba;s/\n/#/g') |
| 89 | + TOKEN="$(echo "$TOKEN_RESULT" | sed s/\#.*$//g | sed s/^Token:\ //)" |
| 90 | + HASHED_TOKEN="$(echo "$TOKEN_RESULT" | sed s/^.*\#//g | sed s/Hashed\ Token:\ //)" |
| 91 | + DEPLOY_ARGS="${DEPLOY_ARGS} --bearer-token ${HASHED_TOKEN}" |
| 92 | + printf "User Token will be:\n%s\nStore this somewhere and use it when calling the Influx server\n" "${TOKEN}" |
| 93 | + echo "export INFLUXDB_TOKEN=${TOKEN}" > influxdb3.token |
| 94 | +fi |
| 95 | + |
| 96 | +if [ ! -d "${DATA_DIR}" ] |
| 97 | +then |
| 98 | + printf "Making data dir %s\n" "${DATA_DIR}" |
| 99 | + mkdir -p ${DATA_DIR} |
| 100 | + RESULT=$? |
| 101 | + if [ "${RESULT}" != 0 ] && [ "${OBJECT_STORE}" == "file" ] |
| 102 | + then |
| 103 | + printf "Failed to create %s when using `file` object store\n" "${DATA_DIR}" |
| 104 | + printf "ABORTING" |
| 105 | + exit ${RESULT} |
| 106 | + fi |
| 107 | +fi |
| 108 | + |
| 109 | +if [ ! -w "${DATA_DIR}" ] && [ "${OBJECT_STORE}" == "file" ] |
| 110 | +then |
| 111 | + printf "Data dir %s is not writable when using `file` object store\n" "${DATA_DIR}" |
| 112 | + print "ABORTING" |
| 113 | + exit 1 |
| 114 | +fi |
| 115 | + |
| 116 | +#${INFLUXDB3_EXE} serve --host-id kk-local --object-store file --data-dir /home/karl/temp/store/db --log-filter DEBUG > influxdb3.log 2>&1 & |
| 117 | +${INFLUXDB3_EXE} serve ${DEPLOY_ARGS} > influxdb3.log 2>&1 & |
| 118 | +echo $! | tee influxdb3.pid |
0 commit comments