#!/bin/sh

# run beep sequence if enabled
/usr/local/sbin/beep.sh stop

# shutdown syshook / plugin scripts
/usr/local/etc/rc.syshook stop

# shutdown rc scripts
/usr/local/etc/rc.opnsense stop

# backup volatile internals
/usr/local/etc/rc.backup_dhcpleases
/usr/local/etc/rc.backup_netflow
/usr/local/etc/rc.backup_rrd

# wait for config lock to release
php -a >/dev/null  << EOF
\$fp = fopen('/conf/config.xml', "a+");
if (flock(\$fp, LOCK_EX)) {
	flock(\$fp, LOCK_UN);
	fclose(\$fp);
}
EOF
