summaryrefslogtreecommitdiff
path: root/net/v2ray/files/v2ray.in
blob: c3c4e679a197bd087343b68090a996c4f4a1d62d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

# PROVIDE: v2ray
# REQUIRE: LOGIN
# KEYWORD: shutdown

# Add these lines to /etc/rc.conf.local or /etc/rc.conf to enable `v2ray':
#
# v2ray_enable (bool):          Set to "NO" by default.
#                               Set it to "YES" to enable v2ray
# v2ray_config (path):          Set to "%%PREFIX%%/etc/v2ray/config.json" by default
#                               Set it to the v2ray server config
# v2ray_logdir (path):		Set to "/var/log/v2ray" by default.
#                               Set it to the directory of v2ray log files
# v2ray_env (str):		Set to "" by default.
#                               Set it to the desired environment variables

. /etc/rc.subr

name="v2ray"
rcvar="${name}_enable"

: ${v2ray_enable="NO"}
: ${v2ray_config="%%PREFIX%%/etc/$name/config.json"}
: ${v2ray_logdir="/var/log/${name}"}
: ${v2ray_env=""}
: ${v2ray_user="%%USER%%"}
: ${v2ray_group="%%GROUP%%"}

asset_env="V2RAY_LOCATION_ASSET=%%PREFIX%%/share/$name"
pidfile="/var/run/$name.pid"
procname="%%PREFIX%%/bin/$name"
command="/usr/sbin/daemon"
command_args="-c -p ${pidfile} /usr/bin/env ${asset_env} ${v2ray_env} ${procname} -config ${v2ray_config}"
required_files="${v2ray_config}"

start_precmd="v2ray_startprecmd"

v2ray_startprecmd() {
	touch "${pidfile}"
	chown ${v2ray_user}:${v2ray_group} "${pidfile}"
	mkdir -p "${v2ray_logdir}"
	chown -R ${v2ray_user}:${v2ray_group} "${v2ray_logdir}"
}

load_rc_config "$name"
run_rc_command "$1"