Your message dated Thu, 9 Jan 2020 17:35:46 +0000
with message-id <db2fa4e2-7b54-b088-1821-4d9f6ef43...@tincho.org>
and subject line Re: Bug#946050: Please add systemd socket activation support
has caused the Debian Bug report #946050,
regarding Please add systemd socket activation support
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact ow...@bugs.debian.org
immediately.)


-- 
946050: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=946050
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
--- Begin Message ---
Package: prometheus-blackbox-exporter
Severity: wishlist
Tags: patch

Hi,

Please consider adding the systemd socket activation patch from
https://github.com/prometheus/blackbox_exporter/pull/523/commits.

The verified working version for both 0.13 and 0.14 is attached.

TIA!

Best regards,
Kilian
backport systemd socket activation from 
https://github.com/prometheus/blackbox_exporter/pull/523
Credit goes to Stefan Bühler
--- a/main.go
+++ b/main.go
@@ -39,6 +39,8 @@ import (
 
        "github.com/prometheus/blackbox_exporter/config"
        "github.com/prometheus/blackbox_exporter/prober"
+
+       "github.com/coreos/go-systemd/activation"
 )
 
 var (
@@ -204,12 +206,16 @@ func init() {
 }
 
 func main() {
-       promlogConfig := promlog.Config{}
-       flag.AddFlags(kingpin.CommandLine, &promlogConfig)
+       os.Exit(run())
+}
+
+func run() int {
+       promlogConfig := &promlog.Config{}
+       flag.AddFlags(kingpin.CommandLine, promlogConfig)
        kingpin.Version(version.Print("blackbox_exporter"))
        kingpin.HelpFlag.Short('h')
        kingpin.Parse()
-       logger := promlog.New(&promlogConfig)
+       logger := promlog.New(promlogConfig)
        rh := &resultHistory{maxResults: *historyLimit}
 
        level.Info(logger).Log("msg", "Starting blackbox_exporter", "version", 
version.Info())
@@ -217,12 +223,12 @@ func main() {
 
        if err := sc.ReloadConfig(*configFile); err != nil {
                level.Error(logger).Log("msg", "Error loading config", "err", 
err)
-               os.Exit(1)
+               return 1
        }
 
        if *configCheck {
                level.Info(logger).Log("msg", "Config file is ok exiting...")
-               os.Exit(0)
+               return 0
        }
 
        level.Info(logger).Log("msg", "Loaded config file")
@@ -329,9 +335,44 @@ func main() {
                w.Write(c)
        })
 
-       level.Info(logger).Log("msg", "Listening on address", "address", 
*listenAddress)
-       if err := http.ListenAndServe(*listenAddress, nil); err != nil {
-               level.Error(logger).Log("msg", "Error starting HTTP server", 
"err", err)
-               os.Exit(1)
+       srv := http.Server{Addr: *listenAddress}
+       srvc := make(chan struct{})
+       term := make(chan os.Signal, 1)
+       signal.Notify(term, os.Interrupt, syscall.SIGTERM)
+
+       go func() {
+               listeners, err := activation.Listeners()
+               if err != nil {
+                       level.Error(logger).Log("msg", "cannot retrieve 
activation listeners", "err", err)
+                       return
+               }
+
+               if len(listeners) > 1 {
+                       level.Error(logger).Log("msg", "unexpected number of 
socket activation listeners", "listeners", len(listeners))
+                       return
+               }
+               if len(listeners) == 1 {
+                       level.Info(logger).Log("msg", "Listening on activation 
socket")
+                       if err := http.Serve(listeners[0], nil); err != 
http.ErrServerClosed {
+                               level.Error(logger).Log("msg", "Error starting 
HTTP server", "err", err)
+                               close(srvc)
+                       }
+               } else {
+                       level.Info(logger).Log("msg", "Listening on address", 
"address", *listenAddress)
+                       if err := srv.ListenAndServe(); err != 
http.ErrServerClosed {
+                               level.Error(logger).Log("msg", "Error starting 
HTTP server", "err", err)
+                               close(srvc)
+                       }
+               }
+       }()
+
+       for {
+               select {
+               case <-term:
+                       level.Info(logger).Log("msg", "Received SIGTERM, 
exiting gracefully...")
+                       return 0
+               case <-srvc:
+                       return 1
+               }
        }
 }

--- End Message ---
--- Begin Message ---
Hi Kilian,

I agree with upstream that this does not seem like a good fit for the
exporter.

As an alternative, you could implement similar functionality by tweaking
how you start the exporter, or configuring your container so you can
access it with a virtual interface.

Hence, I am closing this bug now.

On 03/12/2019 12:12, Kilian Krause wrote:
> Package: prometheus-blackbox-exporter
> Severity: wishlist
> Tags: patch
> 
> Hi,
> 
> Please consider adding the systemd socket activation patch from
> https://github.com/prometheus/blackbox_exporter/pull/523/commits.
> 
> The verified working version for both 0.13 and 0.14 is attached.
> 
> TIA!
> 
> Best regards,
> Kilian
> 

-- 
Martina Ferrari (Tina)

--- End Message ---
_______________________________________________
Pkg-go-maintainers mailing list
Pkg-go-maintainers@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/pkg-go-maintainers

Reply via email to