Skip to content

Commit

Permalink
Merge branch 'oom'
Browse files Browse the repository at this point in the history
  • Loading branch information
local committed Oct 15, 2023
2 parents 1c5e259 + b46613a commit 31e9ef1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions root/etc/init.d/luci_v2ray
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions root/usr/libexec/luci_v2ray/luci_v2ray_entry.sh
Original file line number Diff line number Diff line change
@@ -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}" "$@"

0 comments on commit 31e9ef1

Please sign in to comment.