#!/bin/sh /etc/rc.common # Copyright (C) 2023 Tianling Shen USE_PROCD=1 START=96 STOP=10 extra_command "hot_reload" "Hot-reload service" CONF="dae" PROG="/usr/bin/dae" LOG="/var/log/dae/dae.log" CRON_FILE="/etc/crontabs/root" DAENETNS="/run/netns/daens" RANDOM_SEED=$RANDOM RANDOM_NUM=$((RANDOM_SEED % 10 + 1)) setcron() { touch $CRON_FILE sed -i '/dae hot_reload/d' $CRON_FILE 2>/dev/null [ "$(uci -q get dae.config.subscribe_auto_update)" -eq 1 ] && echo "${RANDOM_NUM} $(uci -q get dae.config.subscribe_update_day_time) * * $(uci -q get dae.config.subscribe_update_week_time) /etc/init.d/dae hot_reload >/dev/null 2>&1" >>$CRON_FILE crontab $CRON_FILE } delcron() { sed -i '/dae hot_reload/d' $CRON_FILE 2>/dev/null crontab $CRON_FILE } set_chmod_640() { chmod -R 640 /etc/dae/ mkdir -p /etc/dae/config.d mkdir -p /var/log/dae } setlocaluse() { uci set dhcp.@dnsmasq[0].localuse="1" uci commit dhcp /etc/init.d/dnsmasq restart } dellocaluse() { local dns_list uci set dhcp.@dnsmasq[0].localuse="0" uci commit dhcp /etc/init.d/dnsmasq restart . /lib/functions/network.sh network_find_wan LOGICAL_WAN || exit 1 dns_list=$(ubus call network.interface.$LOGICAL_WAN status | jsonfilter -e '@["dns-server"]' | sed 's/[]["]//g' | sed 's/,/\n/g' | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b') [ -z "$dns_list" ] && dns_list="119.29.29.29 180.76.76.76 223.5.5.5" grep -v '^nameserver ' /etc/resolv.conf > /tmp/resolv.conf.new.dae 2>/dev/null for dns in $dns_list; do echo "nameserver $dns" >> /tmp/resolv.conf.new.dae done cat /tmp/resolv.conf.new.dae > /etc/resolv.conf rm -f /tmp/resolv.conf.new.dae } start_service() { local enabled config_file log_maxbackups log_maxsize set_chmod_640 uci commit "$CONF" 2>/dev/null config_load "$CONF" config_get_bool enabled "config" "enabled" "0" [ "$enabled" -eq "1" ] || return 1 config_get config_file "config" "config_file" "/etc/dae/config.dae" "$PROG" validate -c "$config_file" || return 1 setcron dellocaluse config_get log_maxbackups "config" "log_maxbackups" "1" config_get log_maxsize "config" "log_maxsize" "1" procd_open_instance "$CONF" uname -r | grep -Eq "^6\.6" && procd_set_param env "QUIC_GO_DISABLE_GSO"="true" procd_set_param env DAE_LOCATION_ASSET="/usr/share/v2ray" procd_set_param command "$PROG" run procd_append_param command --config "$config_file" procd_append_param command --disable-timestamp procd_append_param command --logfile "$LOG" procd_append_param command --logfile-maxbackups "$log_maxbackups" procd_append_param command --logfile-maxsize "$log_maxsize" procd_set_param limits core="unlimited" procd_set_param limits nofile="1000000 1000000" procd_set_param respawn procd_set_param stderr 1 procd_close_instance } stop_service() { delcron setlocaluse [ -f "$DAENETNS" ] && umount "$DAENETNS" } service_triggers() { procd_add_reload_trigger "$CONF" } hot_reload() { set_chmod_640 /etc/init.d/dae running && "$PROG" reload }