fw876 / helloworld

GNU General Public License v3.0
3.7k stars 2.65k forks source link

安装procd-ujail后,dnsmasq无法启动。 #682

Closed acooler15 closed 3 years ago

acooler15 commented 3 years ago

错误信息:

dnsmasq[1]: cannot access directory /var/etc/dnsmasq-ssrplus.d: No such file or directory

错误原因:

安装procd-ujail后,/etc/init.d/dnsmasq文件中的procd_add_jail_mount生效,但是/var/etc/并不在列表中,导致dnsmasq无法读取/var/etc/dnsmasq-ssrplus.d中的内容。

测试:

Test 1

将luci-app-ssr-plus的/root/usr/share/shadowsocksr/update.lua#L12/root/etc/init.d/shadowsocksr#L20TMP_DNSMASQ_PATH的值修改为/var/dnsmasq.d/dnsmasq-ssrplus.d

diff --git a/luci-app-ssr-plus/root/etc/init.d/shadowsocksr b/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
index 7021029..593b5ea 100755
--- a/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
+++ b/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
@@ -17,7 +17,7 @@ LOCK_FILE=/var/lock/ssrplus.lock
 LOG_FILE=/var/log/ssrplus.log
 TMP_PATH=/var/etc/ssrplus
 TMP_BIN_PATH=$TMP_PATH/bin
-TMP_DNSMASQ_PATH=/var/etc/dnsmasq-ssrplus.d
+TMP_DNSMASQ_PATH=/var/dnsmasq.d/dnsmasq-ssrplus.d
 tcp_config_file=
 udp_config_file=
 shunt_config_file=
diff --git a/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua b/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua
index ccf8546..f07bc12 100755
--- a/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua
+++ b/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua
@@ -9,7 +9,7 @@ require "luci.model.uci"
 local icount = 0
 local args = arg[1]
 local uci = luci.model.uci.cursor()
-local TMP_DNSMASQ_PATH = "/var/etc/dnsmasq-ssrplus.d"
+local TMP_DNSMASQ_PATH = "/var/dnsmasq.d/dnsmasq-ssrplus.d"
 local TMP_PATH = "/var/etc/ssrplus"
 -- match comments/title/whitelist/ip address/excluded_domain
 local comment_pattern = "^[!\\[@]+"

结果: 失败。 原因分析: /etc/init.d/dnsmasqdnsmasqconfdir变量的值默认为/tmp/dnsmasq.d

Test 2

将luci-app-ssr-plus的/root/usr/share/shadowsocksr/update.lua#L12/root/etc/init.d/shadowsocksr#L20TMP_DNSMASQ_PATH的值修改为/tmp/dnsmasq.d/dnsmasq-ssrplus.d

diff --git a/luci-app-ssr-plus/root/etc/init.d/shadowsocksr b/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
index 7021029..ffa01a8 100755
--- a/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
+++ b/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
@@ -17,7 +17,7 @@ LOCK_FILE=/var/lock/ssrplus.lock
 LOG_FILE=/var/log/ssrplus.log
 TMP_PATH=/var/etc/ssrplus
 TMP_BIN_PATH=$TMP_PATH/bin
-TMP_DNSMASQ_PATH=/var/etc/dnsmasq-ssrplus.d
+TMP_DNSMASQ_PATH=/tmp/dnsmasq.d/dnsmasq-ssrplus.d
 tcp_config_file=
 udp_config_file=
 shunt_config_file=
@@ -810,8 +810,8 @@ start_rules() {
 start() {
    set_lock
    echolog "----------start------------"
-   mkdir -p /var/run /var/lock /var/log /var/dnsmasq.d $TMP_BIN_PATH $TMP_DNSMASQ_PATH
-   echo "conf-dir=${TMP_DNSMASQ_PATH}" >"/var/dnsmasq.d/dnsmasq-ssrplus.conf"
+   mkdir -p /var/run /var/lock /var/log /tmp/dnsmasq.d $TMP_BIN_PATH $TMP_DNSMASQ_PATH
+   echo "conf-dir=${TMP_DNSMASQ_PATH}" >"/tmp/dnsmasq.d/dnsmasq-ssrplus.conf"
    if load_config; then
        Start_Run
        start_rules
@@ -844,7 +844,7 @@ start() {

 boot() {
    echolog "boot!"
-   mkdir -p /var/run /var/lock /var/log /var/dnsmasq.d $TMP_BIN_PATH $TMP_DNSMASQ_PATH
+   mkdir -p /var/run /var/lock /var/log /tmp/dnsmasq.d $TMP_BIN_PATH $TMP_DNSMASQ_PATH
    ulimit -n 65535
    start
 }
@@ -869,8 +869,8 @@ stop() {
    $PS -w | grep -v "grep" | grep "$TMP_PATH" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
    killall -q -9 v2ray-plugin obfs-local xray-plugin
    rm -f /var/lock/ssr-monitor.lock
-   if [ -f "/var/dnsmasq.d/dnsmasq-ssrplus.conf" ]; then
-       rm -rf /var/dnsmasq.d/dnsmasq-ssrplus.conf $TMP_DNSMASQ_PATH $TMP_PATH/*-ssr-*.json $TMP_PATH/ssr-server*.json
+   if [ -f "/tmp/dnsmasq.d/dnsmasq-ssrplus.conf" ]; then
+       rm -rf /tmp/dnsmasq.d/dnsmasq-ssrplus.conf $TMP_DNSMASQ_PATH $TMP_PATH/*-ssr-*.json $TMP_PATH/ssr-server*.json
        /etc/init.d/dnsmasq restart >/dev/null 2>&1
    fi
    del_cron
diff --git a/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua b/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua
index ccf8546..3e83271 100755
--- a/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua
+++ b/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua
@@ -9,7 +9,7 @@ require "luci.model.uci"
 local icount = 0
 local args = arg[1]
 local uci = luci.model.uci.cursor()
-local TMP_DNSMASQ_PATH = "/var/etc/dnsmasq-ssrplus.d"
+local TMP_DNSMASQ_PATH = "/tmp/dnsmasq.d/dnsmasq-ssrplus.d"
 local TMP_PATH = "/var/etc/ssrplus"
 -- match comments/title/whitelist/ip address/excluded_domain
 local comment_pattern = "^[!\\[@]+"

结果: 成功

Test 3

修改dnsmasq,为其增加一个list类型的配置extra_mount。 基于openwrt/package master 分支

diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
index 3250b2179b..c437719dc6 100644
--- a/package/network/services/dnsmasq/files/dnsmasq.init
+++ b/package/network/services/dnsmasq/files/dnsmasq.init
@@ -954,6 +954,7 @@ dnsmasq_start()
        config_list_foreach "$cfg" "interface" append_interface
        config_list_foreach "$cfg" "notinterface" append_notinterface
    }
+   config_get EXTRA_MOUNT "$cfg" "extra_mount" ""
    config_get_bool ignore_hosts_dir "$cfg" ignore_hosts_dir 0
    if [ "$ignore_hosts_dir" = "1" ]; then
        xappend "--addn-hosts=$HOSTFILE"

结果: 成功

1715173329 commented 3 years ago

The patch of test 2 makes sense.

1715173329 commented 3 years ago

684 should have been fixed this.