Openwrt 启动dae的init.d脚本
- Dominant language
- Go
- Stars
- 6.2k
- Forks
- 402
- Avg merge
- 1h 8m
- Merged PRs (30d)
- 1
Description
Openwrt 启动dae的init.d脚本
一、使用说明: 请把以下内容替换到 /etc/init.d/dae 感谢@[tty228](https://github.com/tty228)给的改进版本,修复了dnsmasq问题
```Bash
#!/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功能)(补充:不需要关,见评论区)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the proposed /etc/init.d/dae OpenWrt rc.common script and review how this repository packages or documents service startup. Check the dae validate, run, reload, suspend, and PID-file commands together with the dnsmasq changes on OpenWrt. Done means an agreed integration location and verified start, stop, restart, and reload behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- devops, operating-systems
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100