Skip to content

Instantly share code, notes, and snippets.

@cntrump
Last active December 26, 2023 23:28
Show Gist options
  • Save cntrump/1a9236d8a2c9b0f650d5cde64ec30dcf to your computer and use it in GitHub Desktop.
Save cntrump/1a9236d8a2c9b0f650d5cde64ec30dcf to your computer and use it in GitHub Desktop.
A simple v2fly daemonizing wrapper for FreeBSD
#!/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"
@cntrump
Copy link
Author

cntrump commented Dec 25, 2023

Useage:

Install nginx: pkg install nginx and then

  1. copy v2fly to /usr/local/etc/rc.d
  2. run chmod +x /usr/local/etc/rc.d/v2fly
  3. add v2fly_eanble="YES" to /etc/rc.conf
  4. add v2flylimits_enable="YES" to /etc/rc.conf
  5. (Optional) run mkdir /var/log/v2fly
  6. run service v2fly start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment