#!/sbin/openrc-run

description="MultiISP load balancing and failover"
command=/usr/sbin/pingu
command_args="-d $pingu_opts"
pidfile=/var/run/pingu/pingu.pid
route_rules=/etc/pingu/route-rules
rundir=${pidfile%/*}

depend() {
	need net
	after firewall
}

start_pre() {
	if ! [ -f "$route_rules" ]; then
		return 0
	fi
	sed -e 's/\#.*//' -e '/^$/d' "$route_rules" | while read line; do
		ebegin "Adding route rule: $line"
		ip rule add $line && echo $line >> $rundir/route-rules
		eend
	done
}

stop_post() {
	if ! [ -f "$rundir"/route-rules ]; then
		return 0
	fi
	while read line; do
		ebegin "Removing route rule: $line"
		ip rule del $line
		eend
	done < "$rundir"/route-rules
	rm "$rundir"/route-rules
}
