prometheus-node-exporter-lua: fix waiting for interface
[feed/packages.git] / utils / prometheus-node-exporter-lua / files / etc / init.d / prometheus-node-exporter-lua
index 582e2116153de47869a0138118d0ccf229eab4d5..7dc8bc199c7f93ea24a7f337f19f26f31bbfc456 100644 (file)
@@ -11,33 +11,33 @@ _log() {
 start_service() {
        . /lib/functions/network.sh
 
-       local interface ipv6 port bind
+       local interface port bind4 bind6
 
        config_load prometheus-node-exporter-lua.main
+       config_get keepalive "main" http_keepalive 70
        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" ] || {
+       [ "$interface" = "*" ] || {
+               network_get_ipaddr  bind4 "$interface"
+               network_get_ipaddr6 bind6 "$interface"
+               [ -n "$bind4$bind6" ] || {
                        _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 --bind ${bind}
-       procd_append_param command --port ${port}
+       procd_set_param command /usr/sbin/uhttpd -f -c /dev/null -l / -L /usr/bin/prometheus-node-exporter-lua
+       [ $keepalive -gt 0 ] && procd_append_param command -k $keepalive
+
+       if [ "$interface" = "*" ]; then
+               procd_append_param command -p $port
+       else
+               [ -n "$bind4" ] && procd_append_param command -p $bind4:$port
+               [ -n "$bind6" ] && procd_append_param command -p [$bind6]:$port
+       fi
 
        procd_set_param stdout 1
        procd_set_param stderr 1