summaryrefslogtreecommitdiffstats
path: root/backends/nc-backend.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbackends/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