Files
akvorado/cmd/conntrack-fixer.go
Vincent Bernat bd37c1d553 common/httpserver: listen on an abstract Unix socket
And make healthcheck command use it by default. This makes the
healthcheck command works whatever port the user has configured for the
HTTP service.
2025-11-24 11:29:45 +01:00

65 lines
1.7 KiB
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
//go:build linux
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"akvorado/common/daemon"
"akvorado/common/httpserver"
"akvorado/common/reporter"
"akvorado/conntrackfixer"
)
var conntrackFixerCmd = &cobra.Command{
Use: "conntrack-fixer",
Short: "Clean conntrack for UDP ports",
Long: `This helper cleans the conntrack entries for the UDP ports exposed by
containers started with the label "akvorado.conntrack.fix=1".`,
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
// This is a simplified service which is not configurable.
r, err := reporter.New(reporter.DefaultConfiguration())
if err != nil {
return fmt.Errorf("unable to initialize reporter: %w", err)
}
daemonComponent, err := daemon.New(r)
if err != nil {
return fmt.Errorf("unable to initialize daemon component: %w", err)
}
httpConfiguration := httpserver.DefaultConfiguration()
httpConfiguration.Listen = ""
httpComponent, err := httpserver.New(r, "conntrack-fixer", httpConfiguration, httpserver.Dependencies{
Daemon: daemonComponent,
})
if err != nil {
return fmt.Errorf("unable to initialize HTTP component: %w", err)
}
conntrackFixerComponent, err := conntrackfixer.New(r,
conntrackfixer.Dependencies{
Daemon: daemonComponent,
HTTP: httpComponent,
})
if err != nil {
return fmt.Errorf("unable to initialize conntrack fixer component: %w", err)
}
addCommonHTTPHandlers(r, "conntrack-fixer", httpComponent)
moreMetrics(r)
components := []any{
httpComponent,
conntrackFixerComponent,
}
return StartStopComponents(r, daemonComponent, components)
},
}
func init() {
RootCmd.AddCommand(conntrackFixerCmd)
}