diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2018-11-07 12:19:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2018-11-07 12:20:17 +0000 |
commit | a64a253794ac64cb40befee54db53bde17dd0d49 (patch) | |
tree | c1024acc5f6e508814b944d99f112259bb28b1be /backends/nc-backend.sh | |
parent | New upstream version 1.10.0+dfsg (diff) | |
download | netdata-upstream/1.11.0+dfsg.tar.xz netdata-upstream/1.11.0+dfsg.zip |
New upstream version 1.11.0+dfsgupstream/1.11.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | backends/nc-backend.sh (renamed from contrib/nc-backend.sh) | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/contrib/nc-backend.sh b/backends/nc-backend.sh index aac5c20bb..7280f86a0 100755 --- a/contrib/nc-backend.sh +++ b/backends/nc-backend.sh @@ -1,5 +1,10 @@ #!/usr/bin/env bash +# SPDX-License-Identifier: GPL-3.0-or-later + +# This is a simple backend database proxy, written in BASH, using the nc command. +# Run the script without any parameters for help. + MODE="${1}" MY_PORT="${2}" BACKEND_HOST="${3}" @@ -25,7 +30,7 @@ mync() { listen_save_replay_forever() { local file="${1}" port="${2}" real_backend_host="${3}" real_backend_port="${4}" ret delay=1 started ended - while [ 1 ] + while true do log "Starting nc to listen on port ${port} and save metrics to ${file}" @@ -35,7 +40,7 @@ listen_save_replay_forever() { if [ -s "${file}" ] then - if [ ! -z "${real_backend_host}" -a ! -z "${real_backend_port}" ] + if [ ! -z "${real_backend_host}" ] && [ ! -z "${real_backend_port}" ] then log "Attempting to send the metrics to the real backend at ${real_backend_host}:${real_backend_port}" @@ -77,6 +82,7 @@ if [ "${MODE}" = "start" ] # only one can use the same file/port at a time { flock -n 9 + # shellcheck disable=SC2181 if [ $? -ne 0 ] then log "Cannot get exclusive lock on file ${FILE}.lock - Am I running multiple times?" @@ -86,7 +92,7 @@ if [ "${MODE}" = "start" ] # save our PID to the lock file echo "$$" >"${FILE}.lock" - listen_save_replay_forever "${FILE}" ${MY_PORT} ${BACKEND_HOST} ${BACKEND_PORT} + listen_save_replay_forever "${FILE}" "${MY_PORT}" "${BACKEND_HOST}" "${BACKEND_PORT}" ret=$? log "listener exited." @@ -103,11 +109,12 @@ elif [ "${MODE}" = "stop" ] { flock -n 9 + # shellcheck disable=SC2181 if [ $? -ne 0 ] then - pid=$(<${FILE}.lock) + pid=$(<"${FILE}".lock) log "Killing process ${pid}..." - kill -TERM -${pid} + kill -TERM "-${pid}" exit 0 fi |