summaryrefslogtreecommitdiff
path: root/utils/prometheus-node-exporter-lua
diff options
context:
space:
mode:
authorAndre Heider <a.heider@gmail.com>2018-12-23 11:43:25 +0100
committerEtienne Champetier <champetier.etienne@gmail.com>2019-11-17 18:16:48 -0800
commit48568ad9f9dfca6cecdcf1eabda629d8ccb77f42 (patch)
tree79c9aa5748f96bc072ef9022463e9687bb836dc8 /utils/prometheus-node-exporter-lua
parentb91b41a71f1a0e755f4945c62656abf6f047937a (diff)
prometheus-node-exporter-lua: switch config to openwrt interface names
Drop the config knob 'listen_address' and introduce 'listen_interface' and 'listen_ipv6' instead. 'listen_interface' takes an openwrt interface name ('loopback', 'lan', 'wan' etc, or "*" for all), from which the primary IP is used to listen on. If 'listen_ipv6' is set to '1', the IPv6 adress will be used, IPv4 elsewise. procd interface triggers are now combined with this, so if the listen interface is not yet configured when the init script is executed, the process start is defered, and the trigger takes care of that once the interface is ready. Fixes #7670 Signed-off-by: Andre Heider <a.heider@gmail.com>
Diffstat (limited to 'utils/prometheus-node-exporter-lua')
-rw-r--r--utils/prometheus-node-exporter-lua/files/etc/config/prometheus-node-exporter-lua3
-rw-r--r--utils/prometheus-node-exporter-lua/files/etc/init.d/prometheus-node-exporter-lua40
2 files changed, 39 insertions, 4 deletions
diff --git a/utils/prometheus-node-exporter-lua/files/etc/config/prometheus-node-exporter-lua b/utils/prometheus-node-exporter-lua/files/etc/config/prometheus-node-exporter-lua
index 1401a1aec..585e29b33 100644
--- a/utils/prometheus-node-exporter-lua/files/etc/config/prometheus-node-exporter-lua
+++ b/utils/prometheus-node-exporter-lua/files/etc/config/prometheus-node-exporter-lua
@@ -1,3 +1,4 @@
config prometheus-node-exporter-lua 'main'
- option listen_address '::1'
+ option listen_interface 'loopback'
+ option listen_ipv6 '0'
option listen_port '9100'
diff --git a/utils/prometheus-node-exporter-lua/files/etc/init.d/prometheus-node-exporter-lua b/utils/prometheus-node-exporter-lua/files/etc/init.d/prometheus-node-exporter-lua
index a1a47079c..f4cd1c94c 100644
--- a/utils/prometheus-node-exporter-lua/files/etc/init.d/prometheus-node-exporter-lua
+++ b/utils/prometheus-node-exporter-lua/files/etc/init.d/prometheus-node-exporter-lua
@@ -4,19 +4,53 @@
START=60
USE_PROCD=1
+. /lib/functions/network.sh
+
+_log() {
+ logger -p daemon.info -t prometheus-node-exporter-lua "$@"
+}
+
start_service() {
- procd_open_instance
+ local interface ipv6 port bind
config_load prometheus-node-exporter-lua.main
- config_get bind "main" listen_address ::1
+ config_get interface "main" listen_interface "loopback"
+ config_get_bool ipv6 "main" listen_ipv6 0
config_get port "main" listen_port 9100
+ if [ "$interface" = "*" ]; then
+ [ "$ipv6" = 1 ] && bind="::" || bind="0.0.0.0"
+ else
+ if [ "$ipv6" = 1 ]; then
+ network_get_ipaddr6 bind "$interface"
+ else
+ network_get_ipaddr bind "$interface"
+ fi
+
+ network_is_up "$interface" && [ -n "$bind" ] || {
+ _log "defering start until listen interface $interface becomes ready"
+ return 0
+ }
+ fi
+
+ procd_open_instance
+
procd_set_param command /usr/bin/prometheus-node-exporter-lua
- procd_append_param command --port ${port}
procd_append_param command --bind ${bind}
+ procd_append_param command --port ${port}
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
+
+service_triggers()
+{
+ local interface
+
+ config_load prometheus-node-exporter-lua.main
+ config_get interface "main" listen_interface "loopback"
+
+ [ "$interface" = "*" ] || procd_add_reload_interface_trigger "$interface"
+}