daeuniverse/dae

Openwrt 启动dae的init.d脚本

youwei5683 opened this issue · 4 comments

Openwrt 启动dae的init.d脚本

一、使用说明: 请把以下内容替换到 /etc/init.d/dae 感谢@tty228给的改进版本,修复了dnsmasq问题

#!/bin/sh /etc/rc.common

START=99
STOP=99

LOG_FILE="/var/log/dae.log"
# 如果不需要生成日志,取消下一行的注释
#LOG_FILE="/dev/null"

start_pre() {
   if ! /usr/bin/dae validate -c /etc/dae/config.dae; then
      echo "dae config file /etc/dae/config.dae is invalid or too open, exiting."
      exit 1
   fi
}

start() {
    # 检查 dae 进程是否已经在运行
    if [ $(pidof /usr/bin/dae) ]; then
        echo "dae process is already running!"
        return 1
    fi
	# 清空并添加 DNS 转发,否则关闭劫持后,会因无网络无法启动 dae
	uci -q del dhcp.@dnsmasq[0].server
	uci add_list dhcp.@dnsmasq[0].server='223.5.5.5'
	# 关闭 OpenWrt dnsmasq 53 劫持
	uci set dhcp.@dnsmasq[0].noresolv='1'
	uci commit dhcp
	/etc/init.d/dnsmasq reload
	echo "Disable the 'noresolv' feature in Dnsmasq"
	# 清空日志,自选
	echo "" > $LOG_FILE
	# 启动 dae 进程,并将日志输出到 LOG_FILE 文件中
	start_pre
	/usr/bin/dae run --disable-timestamp -c /etc/dae/config.dae >> $LOG_FILE 2>&1 &
	echo "Started dae process."

	# 记录进程 PID
	echo $! > /var/run/dae.pid
   
}

stop() {
	# 停止 dae 进程
	if [ -f /var/run/dae.pid ]; then
		pid=$(cat /var/run/dae.pid)
		
		kill -15 $pid
		echo "dae stopped"
		# 清空添加的 DNS 转发,并恢复 noresolv 功能
		uci -q del dhcp.@dnsmasq[0].server
		uci set dhcp.@dnsmasq[0].noresolv='0'
		uci commit dhcp
		/etc/init.d/dnsmasq reload
		echo "Enable the 'noresolv' feature in Dnsmasq"
	else
		echo "dae is not running"
	fi

    # 删除进程 PID 文件
    rm -f /var/run/dae.pid
}

restart() {
    stop
    sleep 1
    start
}

reload() {
    # 从 PID 文件中读取进程 ID
    if [ -f /var/run/dae.pid ]; then
        pid=$(cat /var/run/dae.pid)

        # 重新加载 dae 进程
        /usr/bin/dae reload $pid
        echo "Reloaded dae process."
    else
        echo "dae process is not running!"
    fi
}

二、扩展功能:
1.暂停dae: /usr/bin/dae suspend $(cat /var/run/dae.pid)
2.查看日志: tail -f /var/log/dae.log
(ps:自己注意dae日志文件大小 ,已知问题OPENWRT下日志文件大于512M dae会崩,建议安装第三方日志管理软件)

以下废弃。。
三、目前已知dae会和Dnsmasq发生冲突
1.

echo "nameserver 223.5.5.5" > /etc/resolv.conf

2.建议把 Dnsmasq DNS监听端口设置为 0 或者 /etc/init.d/dnsmasq stop (ps:慎用!!!可能会失去dhcp功能)(补充:不需要关,见评论区)

sbwml commented

一个简易的 DAE OpenWrt LuCI https://github.com/sbwml/luci-app-dae

dae

或者把 dnsmasq 的劫持关了,见 #171 (comment)

以及关掉这个:
image

hcym commented

ipv6好像不行

dae 0.5.1+: https://gist.github.com/douglarek/764d898c406b4aa3d0e707b3c282215d .

[2023-01-27] update: use uci del dhcp.@dnsmasq[0].domain to delete local domain suffix. see #448

[2024-03-01] update: after #458 , no magical modifications are needed. A better startup script can be found here: https://github.com/immortalwrt/packages/blob/master/net/dae/files/dae.init .