From c3c466abb9397ba5cd4dd870b9955ea7d4b72f97 Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Wed, 13 Jan 2021 11:15:54 -0500 Subject: [PATCH 01/11] add python wrapper --- Dockerfile | 2 ++ README.md | 2 ++ bin/nuocd | 31 +++++++++++++++++++++++++++++++ conf/nuodb.conf | 8 ++++---- tests/ci/install_nuocd.sh | 1 + 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100755 bin/nuocd diff --git a/Dockerfile b/Dockerfile index 1c8d603..6114da5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,8 @@ COPY --chown=telegraf:0 conf/telegraf.conf /etc/telegraf/telegraf.conf COPY --chown=telegraf:0 conf/nuodb.conf /etc/telegraf/telegraf.d/static/nuodb.conf COPY --chown=telegraf:0 conf/outputs.conf /etc/telegraf/telegraf.d/dynamic/outputs.conf +COPY --chown=telegraf:0 bin/nuocd /usr/local/bin/nuocd + USER 1000:0 CMD ["telegraf", "--config", "/etc/telegraf/telegraf.conf", "--config-directory", "/etc/telegraf/telegraf.d"] diff --git a/README.md b/README.md index cf54637..3ce43f4 100644 --- a/README.md +++ b/README.md @@ -221,10 +221,12 @@ sudo cp -r nuocd /opt/ The `conf/nuodb.conf` file in this repository configures all four input plugins for NuoDB running on localhost as described in the section above. The `conf/outputs.conf` file configures an output plugin to a InfluxDB instance defined by the `$INFLUXURL` environment variable. +The `bin/nuocd` file is a convenience wrapper for python. Replace the `` placeholder in the `INFLUXURL` line below with the hostname of the machine running the InfluxDB instance, and then run the commands. ``` sudo cp conf/nuodb.conf /etc/telegraf/telegraf.d sudo cp conf/outputs.conf /etc/telegraf/telegraf.d +sudo cp bin/nuocd /usr/local/bin/nuocd sudo chown -R telegraf.telegraf /etc/telegraf cat </etc/default/telegraf INFLUXURL=http://:8086 diff --git a/bin/nuocd b/bin/nuocd new file mode 100755 index 0000000..a96dd97 --- /dev/null +++ b/bin/nuocd @@ -0,0 +1,31 @@ +#!/bin/sh +# +# (C) Copyright NuoDB, Inc. 2020-2021 All Rights Reserved + +# Unfortunately, ksh93 defines builtin aliases even when run non-interactively. +unalias -a + +die () { echo "$*"; exit 1; } + +# Find the installation directory. +CMD=${0##*/} +DIR=$(cd "${0%$CMD}." && pwd) + +_home=$NUODB_HOME +if test -z "$_home"; then + test -f "${DIR%/*}"/bin/nuodb && _home=${DIR%/*} || _home=/opt/nuodb +fi + +if test -z "$NUOPYTHON" && test -x "$_home/etc/python/nuopython"; then + # nuopython sets up local site-packages for us + _python="$_home/etc/python/nuopython" +else + _python=${NUOPYTHON:-$PYTHON} + if test -z "$_python"; then + _python=$(command -v python2.7) || _python=$(command -v python) \ + || die "Python must be installed" + fi + +fi + +exec "$_python" "$@" diff --git a/conf/nuodb.conf b/conf/nuodb.conf index 114accd..5ea571c 100644 --- a/conf/nuodb.conf +++ b/conf/nuodb.conf @@ -3,7 +3,7 @@ # the helm chart. probably want to put into different files. [[inputs.execd]] - command = [ "python", "/opt/nuocd/nuodb_adminquery.py", "-i", "0", "metrics" ] + command = [ "nuocd", "/opt/nuocd/nuodb_adminquery.py", "-i", "0", "metrics" ] signal = "none" restart_delay = "10s" data_format = "influx" @@ -11,7 +11,7 @@ db_tag = "nuodb" [[inputs.execd]] - command = [ "python", "/opt/nuocd/nuodb_adminquery.py", "-i", "30", "msgtrace" ] + command = [ "nuocd", "/opt/nuocd/nuodb_adminquery.py", "-i", "30", "msgtrace" ] signal = "none" restart_delay = "10s" @@ -29,7 +29,7 @@ db_tag = "nuodb_internal" [[inputs.execd]] - command = [ "python", "/opt/nuocd/nuodb_adminquery.py", "-i", "30", "synctrace" ] + command = [ "nuocd", "/opt/nuocd/nuodb_adminquery.py", "-i", "30", "synctrace" ] signal = "none" restart_delay = "10s" @@ -49,7 +49,7 @@ db_tag = "nuodb_internal" [[inputs.execd]] - command = [ "python", "/opt/nuocd/nuodb_threads.py" ] + command = [ "nuocd", "/opt/nuocd/nuodb_threads.py" ] signal = "none" restart_delay = "10s" diff --git a/tests/ci/install_nuocd.sh b/tests/ci/install_nuocd.sh index bc09304..71b0bf5 100755 --- a/tests/ci/install_nuocd.sh +++ b/tests/ci/install_nuocd.sh @@ -9,6 +9,7 @@ pip install -r requirements.txt sudo cp conf/nuodb.conf /etc/telegraf/telegraf.d sudo cp conf/outputs.conf /etc/telegraf/telegraf.d +sudo cp bin/nuocd /usr/local/bin/nuocd sudo systemctl daemon-reload sudo systemctl stop telegraf From 49587f496e349016939b07f7049f1fc1da671c8f Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Wed, 13 Jan 2021 12:11:53 -0500 Subject: [PATCH 02/11] invert priority --- bin/nuocd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/nuocd b/bin/nuocd index a96dd97..0df79d3 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -22,10 +22,9 @@ if test -z "$NUOPYTHON" && test -x "$_home/etc/python/nuopython"; then else _python=${NUOPYTHON:-$PYTHON} if test -z "$_python"; then - _python=$(command -v python2.7) || _python=$(command -v python) \ + _python=$(command -v python) || _python=$(command -v python2.7) \ || die "Python must be installed" fi - fi exec "$_python" "$@" From 66344c7a68f8f091ab5560384b129cb4abc382fe Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Wed, 13 Jan 2021 13:32:14 -0500 Subject: [PATCH 03/11] invert priority --- bin/nuocd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/nuocd b/bin/nuocd index 0df79d3..8474bc8 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -27,4 +27,6 @@ else fi fi +echo "Found $_python" + exec "$_python" "$@" From d4578a24f530d0ebc2546cd8a3ebc7f0ee50bc99 Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Wed, 13 Jan 2021 13:55:25 -0500 Subject: [PATCH 04/11] simplify --- bin/nuocd | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/bin/nuocd b/bin/nuocd index 8474bc8..ad84a7f 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -7,26 +7,9 @@ unalias -a die () { echo "$*"; exit 1; } -# Find the installation directory. -CMD=${0##*/} -DIR=$(cd "${0%$CMD}." && pwd) - -_home=$NUODB_HOME -if test -z "$_home"; then - test -f "${DIR%/*}"/bin/nuodb && _home=${DIR%/*} || _home=/opt/nuodb -fi - -if test -z "$NUOPYTHON" && test -x "$_home/etc/python/nuopython"; then - # nuopython sets up local site-packages for us - _python="$_home/etc/python/nuopython" -else - _python=${NUOPYTHON:-$PYTHON} - if test -z "$_python"; then - _python=$(command -v python) || _python=$(command -v python2.7) \ - || die "Python must be installed" - fi -fi +_python=$(command -v python) || _python=$(command -v python2) || _python=$(command -v python2.7) \ + || die "Python must be installed" echo "Found $_python" -exec "$_python" "$@" +exec "$_python" "$@" \ No newline at end of file From 774435767b8bde36df180231bb8c4646e2f7419f Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Wed, 13 Jan 2021 14:06:22 -0500 Subject: [PATCH 05/11] simplify --- bin/nuocd | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/nuocd b/bin/nuocd index ad84a7f..6276578 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -7,8 +7,11 @@ unalias -a die () { echo "$*"; exit 1; } -_python=$(command -v python) || _python=$(command -v python2) || _python=$(command -v python2.7) \ - || die "Python must be installed" + +_python=${$PYTHON} +if test -z "$_python"; then + _python=$(command -v python2.7) || _python=$(command -v python2) || _python=$(command -v python) \ + || die "Python must be installed" echo "Found $_python" From e4ac09bebaec512110f7f9045ef5a5ecfb402519 Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Wed, 13 Jan 2021 14:39:04 -0500 Subject: [PATCH 06/11] simplify --- bin/nuocd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/nuocd b/bin/nuocd index 6276578..5c969ba 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -13,6 +13,6 @@ if test -z "$_python"; then _python=$(command -v python2.7) || _python=$(command -v python2) || _python=$(command -v python) \ || die "Python must be installed" -echo "Found $_python" +echo "Found $_python" >&2 exec "$_python" "$@" \ No newline at end of file From 5b07a21ff4ab5e44d5338e056b516d09b19cf73a Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Wed, 13 Jan 2021 16:35:55 -0500 Subject: [PATCH 07/11] fix --- bin/nuocd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/nuocd b/bin/nuocd index 5c969ba..d62352c 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -8,7 +8,7 @@ unalias -a die () { echo "$*"; exit 1; } -_python=${$PYTHON} +_python=${PYTHON} if test -z "$_python"; then _python=$(command -v python2.7) || _python=$(command -v python2) || _python=$(command -v python) \ || die "Python must be installed" From 405f8a1c3ebb798942b9dc66e52e3bd7f2e41ca9 Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Wed, 13 Jan 2021 17:11:14 -0500 Subject: [PATCH 08/11] remove the override --- bin/nuocd | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/nuocd b/bin/nuocd index d62352c..7de1632 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -8,10 +8,9 @@ unalias -a die () { echo "$*"; exit 1; } -_python=${PYTHON} -if test -z "$_python"; then - _python=$(command -v python2.7) || _python=$(command -v python2) || _python=$(command -v python) \ - || die "Python must be installed" + +_python=$(command -v python2.7) || _python=$(command -v python2) || _python=$(command -v python) \ + || die "Python must be installed" echo "Found $_python" >&2 From eed725a1977bb50aea7d22b498841e602746cf47 Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Fri, 15 Jan 2021 11:06:33 -0500 Subject: [PATCH 09/11] hopefully the final form --- bin/nuocd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/nuocd b/bin/nuocd index 7de1632..6b4e6c5 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -7,10 +7,11 @@ unalias -a die () { echo "$*"; exit 1; } - - -_python=$(command -v python2.7) || _python=$(command -v python2) || _python=$(command -v python) \ +_python=${PYTHON} +if test -z "$_python"; then + _python=$(command -v python2.7) || _python=$(command -v python2) || _python=$(command -v python) \ || die "Python must be installed" +fi echo "Found $_python" >&2 From cbf9d14f0a1e449d3eac7e10e0aa9be0df00cc74 Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Fri, 15 Jan 2021 11:08:39 -0500 Subject: [PATCH 10/11] one more place --- conf/telegraf.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/telegraf.conf b/conf/telegraf.conf index c27fe50..657fd4c 100644 --- a/conf/telegraf.conf +++ b/conf/telegraf.conf @@ -17,7 +17,7 @@ [[inputs.execd]] # no input, setups webserver on 0.0.0.0:5000/reload to reload configuration file via url. - command = [ "python", "/opt/nuocd/telegraf_reload.py" ] + command = [ "nuocd", "/opt/nuocd/telegraf_reload.py" ] signal = "none" restart_delay = "10s" From 5e2b4c28ddea65019dcff66ad9cdc2ef0e9f61d5 Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Tue, 19 Jan 2021 13:23:56 -0500 Subject: [PATCH 11/11] remove debug print --- bin/nuocd | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/nuocd b/bin/nuocd index 6b4e6c5..93662b9 100755 --- a/bin/nuocd +++ b/bin/nuocd @@ -13,6 +13,4 @@ if test -z "$_python"; then || die "Python must be installed" fi -echo "Found $_python" >&2 - -exec "$_python" "$@" \ No newline at end of file +exec "$_python" "$@"