diff --git a/root/etc/init.d/luci_v2ray b/root/etc/init.d/luci_v2ray index f401775..5ff0b7a 100755 --- a/root/etc/init.d/luci_v2ray +++ b/root/etc/init.d/luci_v2ray @@ -2589,13 +2589,14 @@ start_instance() { TRANSPARENT_PROXY_EXPECTED=1 procd_open_instance "$NAME.$section" - procd_set_param command "$v2ray_file" + procd_set_param command "/usr/libexec/luci_v2ray/luci_v2ray_entry.sh" + procd_append_param env V2RAY_BIN_FILE="$v2ray_file" procd_append_param command "run" procd_append_param command "--config=$temp_config" procd_set_param respawn if [ -n "$asset_location" ] && [ -d "$asset_location" ]; then - procd_set_param env V2RAY_LOCATION_ASSET="$asset_location" + procd_append_param env V2RAY_LOCATION_ASSET="$asset_location" fi # cat /proc/PID/limits to see if limits works @@ -2606,14 +2607,17 @@ start_instance() { local mem_total="$(awk '/MemTotal/ {print $2}' /proc/meminfo)" if [ -n "$mem_total" ]; then local use_mem_in_kib="$(expr $mem_total \* $mem_percentage \/ 100)" - procd_set_param env GOMEMLIMIT="${use_mem_in_kib}KiB" + procd_append_param env GOMEMLIMIT="${use_mem_in_kib}KiB" fi fi + procd_append_param env OOM_SCORE_ADJ=-999 + procd_set_param file "$temp_config" procd_set_param stderr 1 # forward stderr of the command to logd procd_set_param stdout 1 procd_set_param pidfile "/var/run/${NAME}.${section}.pid" + procd_append_param env "V2RAY_PID_FILE=/var/run/${NAME}.${section}.pid" procd_close_instance } diff --git a/root/usr/libexec/luci_v2ray/luci_v2ray_entry.sh b/root/usr/libexec/luci_v2ray/luci_v2ray_entry.sh new file mode 100644 index 0000000..ce2d80d --- /dev/null +++ b/root/usr/libexec/luci_v2ray/luci_v2ray_entry.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +OOM_SCORE_ADJ=${OOM_SCORE_ADJ:-0} +V2RAY_BIN_FILE=${V2RAY_BIN_FILE:-/usr/bin/v2ray} +V2RAY_PID_FILE=${V2RAY_PID_FILE:-/var/run/luci_v2ray.main.pid} + +pid=$(cat ${V2RAY_PID_FILE}) +echo "${OOM_SCORE_ADJ}" > "/proc/${pid}/oom_score_adj" + +exec "${V2RAY_BIN_FILE}" "$@"