internal/router: only do cleanup in cd mode on freebsd

This commit is contained in:
Cuong Manh Le
2023-07-28 18:57:13 +00:00
committed by Cuong Manh Le
parent c271896551
commit 774f07dd7f
2 changed files with 16 additions and 4 deletions

View File

@@ -283,13 +283,13 @@ func initCLI() {
rootCertPool = cp
}
p.onStarted = append(p.onStarted, func() {
mainLog.Load().Debug().Msg("router setup")
mainLog.Load().Debug().Msg("router setup on start")
if err := p.router.Setup(); err != nil {
mainLog.Load().Error().Err(err).Msg("could not configure router")
}
})
p.onStopped = append(p.onStopped, func() {
mainLog.Load().Debug().Msg("router cleanup")
mainLog.Load().Debug().Msg("router cleanup on stop")
if err := p.router.Cleanup(); err != nil {
mainLog.Load().Error().Err(err).Msg("could not cleanup router")
}

View File

@@ -109,7 +109,7 @@ func (or *osRouter) Setup() error {
}
func (or *osRouter) Cleanup() error {
if or.cfg.FirstListener().IsDirectDnsListener() {
if or.cdMode {
_ = exec.Command(unboundRcPath, "onerestart").Run()
_ = exec.Command(dnsmasqRcPath, "onerestart").Run()
}
@@ -129,10 +129,22 @@ name="{{.Name}}"
rcvar="${name}_enable"
{{.Name}}_env="IS_DAEMON=1"
pidfile="/var/run/${name}.pid"
child_pidfile="/var/run/${name}_child.pid"
command="/usr/sbin/daemon"
daemon_args="-P ${pidfile} -r -t \"${name}: daemon\"{{if .WorkingDirectory}} -c {{.WorkingDirectory}}{{end}}"
daemon_args="-P ${pidfile} -p ${child_pidfile} -t \"${name}: daemon\"{{if .WorkingDirectory}} -c {{.WorkingDirectory}}{{end}}"
command_args="${daemon_args} {{.Path}}{{range .Arguments}} {{.}}{{end}}"
stop_cmd="ctrld_stop"
ctrld_stop() {
pid=$(cat ${pidfile})
child_pid=$(cat ${child_pidfile})
if [ -e "${child_pidfile}" ]; then
kill -s TERM "${child_pid}"
wait_for_pids "${child_pid}" "${pidfile}"
fi
}
load_rc_config "${name}"
run_rc_command "$1"
`