#!/sbin/openrc-run

name="Xray Daemon"
description="A unified platform for anti-censorship"

supervisor=supervise-daemon
respawn_delay=5
respawn_max=2
respawn_period=600

pidfile="/run/${RC_SVCNAME}.pid"
rc_ulimit="-n 1024000 -u 1024000"
capabilities="^cap_net_bind_service,^cap_net_admin,^cap_net_raw"
extra_commands="checkconfig"

env=${env:-"XRAY_LOCATION_ASSET=/usr/share/xray/"}
confdir=${confdir:-"/etc/xray/"}
command="/usr/bin/xray"
command_user="xray:xray"
command_args="run -confdir $confdir"
required_files="$confdir"

depend() {
	need net
	want dns ntp-client
	after firewall
}

checkconfig() {
	export $env
	$command $command_args -test
	eend $?
}

start_pre() {
	checkconfig || return 1
	checkpath -d -m 0750 -o xray:xray /var/log/xray
}
