#!/bin/sh /etc/rc.common
# R-VPN Lite for routers: the Auto tunnel of the R-VPN Lite app for the whole home network
# (/usr/lib/rvpn/rvpn-router run). Sign-in and the switch are on the router's page (Services → R-VPN Lite).
START=95
STOP=10
USE_PROCD=1
PROG=/usr/lib/rvpn/rvpn-router

start_service() {
	local enabled
	config_load rvpn
	config_get_bool enabled main enabled 1
	# A crashed run may have left the home network's DNS pointed at the tunnel: start clean.
	/usr/lib/rvpn/rvpn-hook down
	[ "$enabled" = 1 ] || return 0
	procd_open_instance
	procd_set_param command "$PROG" run
	procd_set_param respawn 3600 5 0
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}

stop_service() {
	/usr/lib/rvpn/rvpn-hook down
}

service_triggers() {
	procd_add_reload_trigger rvpn
}
