92 lines
2.2 KiB
Desktop File
92 lines
2.2 KiB
Desktop File
#!/system/bin/sh
|
|
|
|
proxy_port="65534"
|
|
work_path="`dirname $0`"
|
|
bin_name="v2ray-dns.keeper"
|
|
bin_file="${work_path}/${bin_name}"
|
|
run_path="/data/v2ray/run"
|
|
pid_file="${run_path}/dns-keeper.pid"
|
|
log_file="${run_path}/dns-keeper.log"
|
|
handle_script="${work_path}/v2ray-dns.handle"
|
|
|
|
find_netstat_path() {
|
|
[ -f /system/bin/netstat ] && alias netstat="/system/bin/netstat" && return 0
|
|
[ -f /system/xbin/netstat ] && alias netstat="/system/xbin/netstat" && return 0
|
|
return 1
|
|
}
|
|
|
|
probe_keeper_alive() {
|
|
[ -f ${pid_file} ] && cmd_file="/proc/`cat ${pid_file}`/cmdline" || return 1
|
|
[ -f ${cmd_file} ] && grep -q "v2ray-dns.keeper" ${cmd_file} && return 0 || return 1
|
|
}
|
|
|
|
probe_v2ray_listen() {
|
|
find_netstat_path || return
|
|
v2ray_listen=`netstat -unlp | grep v2ray`
|
|
if eval "echo \"${v2ray_listen}\" | grep -q :::${proxy_port}" || eval "echo \"${v2ray_listen}\" | grep -q 0.0.0.0:${proxy_port}" ; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
display_keeper_pid() {
|
|
if probe_keeper_alive ; then
|
|
echo "[Info]: ${bin_name} service is running. ( PID: `cat ${pid_file}` )"
|
|
return 0
|
|
else
|
|
echo "[Info]: ${bin_name} service is stopped."
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
start_service() {
|
|
if probe_keeper_alive ; then
|
|
echo "[Info]: ${bin_name} service is running. ( PID: `cat ${pid_file}` )"
|
|
return 0
|
|
elif probe_v2ray_listen ; then
|
|
echo "[Info]: Starting ${bin_name} service."
|
|
mkdir -p ${run_path}
|
|
nohup ${bin_file} -d "${handle_script} enable" &>${log_file} &
|
|
echo -n $! > ${pid_file}
|
|
if probe_keeper_alive ; then
|
|
echo "[Info]: ${bin_name} service is running. ( PID: `cat ${pid_file}` )"
|
|
return 0
|
|
else
|
|
echo "[Error]: Start ${bin_name} service Failed."
|
|
rm -f ${pid_file}
|
|
return 1
|
|
fi
|
|
else
|
|
echo "[Error]: V2Ray service is not listening on port ${proxy_port} for DNS proxy."
|
|
exit 1
|
|
return 2
|
|
fi
|
|
}
|
|
|
|
stop_service() {
|
|
if display_keeper_pid ; then
|
|
echo "[Info]: Stopping ${bin_name} service."
|
|
kill `cat ${pid_file}`
|
|
sleep 1
|
|
display_keeper_pid
|
|
fi
|
|
${handle_script} disable
|
|
rm -f ${pid_file}
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
start_service
|
|
;;
|
|
stop)
|
|
stop_service
|
|
;;
|
|
status)
|
|
display_keeper_pid
|
|
;;
|
|
*)
|
|
echo "$0: usage: $0 {start|stop|status}"
|
|
;;
|
|
esac
|