53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// ---------------------------------------------------------------------
|
|
// routes systemd unit name resolution
|
|
// ---------------------------------------------------------------------
|
|
|
|
// EN: Resolve routes service/timer unit names from preferred/active iface.
|
|
// EN: Env overrides still have top priority for custom deployments.
|
|
// RU: Вычисление имен unit для routes service/timer по preferred/active iface.
|
|
// RU: Для кастомных окружений сохраняется приоритет переменных окружения.
|
|
|
|
func resolveRoutesUnitIface() (string, string) {
|
|
st := loadTrafficModeState()
|
|
if pref := normalizePreferredIface(st.PreferredIface); pref != "" {
|
|
return pref, "preferred"
|
|
}
|
|
if statusIface := statusIfaceFromFile(); statusIface != "" && statusIface != "-" {
|
|
return statusIface, "status"
|
|
}
|
|
if active, reason := resolveTrafficIface(""); active != "" {
|
|
return active, reason
|
|
}
|
|
return "", "iface-not-found"
|
|
}
|
|
|
|
func routesServiceUnitName() string {
|
|
if forced := strings.TrimSpace(os.Getenv(routesServiceEnv)); forced != "" {
|
|
return forced
|
|
}
|
|
iface, _ := resolveRoutesUnitIface()
|
|
if iface == "" {
|
|
return ""
|
|
}
|
|
return fmt.Sprintf(routesServiceTemplate, iface)
|
|
}
|
|
|
|
func routesTimerUnitName() string {
|
|
if forced := strings.TrimSpace(os.Getenv(routesTimerEnv)); forced != "" {
|
|
return forced
|
|
}
|
|
iface, _ := resolveRoutesUnitIface()
|
|
if iface == "" {
|
|
return ""
|
|
}
|
|
return fmt.Sprintf(routesTimerTemplate, iface)
|
|
}
|