Last active
December 26, 2023 23:28
-
-
Save cntrump/1a9236d8a2c9b0f650d5cde64ec30dcf to your computer and use it in GitHub Desktop.
A simple v2fly daemonizing wrapper for FreeBSD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# PROVIDE: v2fly | |
# REQUIRE: LOGIN cleanvar | |
# KEYWORD: shutdown | |
. /etc/rc.subr | |
name="v2fly" | |
rcvar="v2fly_enable" | |
[ -z "$v2fly_enable" ] && v2fly_enable="NO" | |
[ -z "$v2flylimits_enable" ] && v2flylimits_enable="NO" | |
[ -z "$v2flylimits_args" ] && v2flylimits_args="-e -U www" | |
pidfile="/var/run/${name}.pid" | |
required_files=/opt/v2fly/etc/config.json | |
v2fly_cmd="/opt/v2fly/bin/v2fly run -c /opt/v2fly/etc/config.json -format jsonv5" | |
command="/usr/sbin/daemon" | |
command_args="-fr -u www -P ${pidfile} ${v2fly_cmd}" | |
start_precmd="v2fly_prestart" | |
start_cmd="v2fly_start" | |
v2fly_prestart() { | |
if checkyesno v2flylimits_enable; then | |
eval `/usr/bin/limits ${v2flylimits_args}` 2>/dev/null | |
else | |
return 0 | |
fi | |
} | |
v2fly_start() { | |
${command} ${command_args} | |
} | |
load_rc_config $name | |
run_rc_command "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useage:
Install
nginx
:pkg install nginx
and thenv2fly
to/usr/local/etc/rc.d
chmod +x /usr/local/etc/rc.d/v2fly
v2fly_eanble="YES"
to/etc/rc.conf
v2flylimits_enable="YES"
to/etc/rc.conf
mkdir /var/log/v2fly
service v2fly start