all: ensure ctrld started after mongodb on Ubios

Because ctrld needs to query custom client mapping from it.

While at it, also make the error message clearer when initializing ubios
discover failed, by attaching the command output to returned error.
This commit is contained in:
Cuong Manh Le
2025-02-13 00:46:56 +07:00
committed by Cuong Manh Le
parent 3403b2039d
commit 4ebe2fb5f4
4 changed files with 23 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ import (
"tailscale.com/health"
"github.com/Control-D-Inc/ctrld/internal/dns"
"github.com/Control-D-Inc/ctrld/internal/router"
)
func init() {
@@ -39,6 +40,9 @@ func setDependencies(svc *service.Config) {
svc.Dependencies = append(svc.Dependencies, "Wants=systemd-networkd-wait-online.service")
}
}
if routerDeps := router.ServiceDependencies(); len(routerDeps) > 0 {
svc.Dependencies = append(svc.Dependencies, routerDeps...)
}
}
func setWorkingDirectory(svc *service.Config, dir string) {

View File

@@ -3,6 +3,7 @@ package clientinfo
import (
"bytes"
"encoding/json"
"fmt"
"io"
"os/exec"
"strings"
@@ -44,9 +45,9 @@ func (u *ubiosDiscover) refreshDevices() error {
cmd := exec.Command("/usr/bin/mongo", "localhost:27117/ace", "--quiet", "--eval", `
DBQuery.shellBatchSize = 256;
db.user.find({name: {$exists: true, $ne: ""}}, {_id:0, mac:1, name:1});`)
b, err := cmd.Output()
b, err := cmd.CombinedOutput()
if err != nil {
return err
return fmt.Errorf("out: %s, err: %w", string(b), err)
}
return u.storeDevices(bytes.NewReader(b))
}

View File

@@ -215,6 +215,20 @@ func LeaseFilesDir() string {
return ""
}
// ServiceDependencies returns list of dependencies that ctrld services needs on this router.
// See https://pkg.go.dev/github.com/kardianos/service#Config for list format.
func ServiceDependencies() []string {
if Name() == ubios.Name {
// On Ubios, ctrld needs to start after unifi-mongodb,
// so it can query custom client info mapping.
return []string{
"Wants=unifi-mongodb.service",
"After=unifi-mongodb.service",
}
}
return nil
}
func distroName() string {
switch {
case bytes.HasPrefix(unameO(), []byte("DD-WRT")):

View File

@@ -219,6 +219,8 @@ const ubiosBootSystemdService = `[Unit]
Description=Run ctrld On Startup UDM
Wants=network-online.target
After=network-online.target
Wants=unifi-mongodb
After=unifi-mongodb
StartLimitIntervalSec=500
StartLimitBurst=5