Main problem of Entware and Tomato: scripts launched before timesync. Therefore, Netdata removes last saved data and starting from scratch
- timeout packet from Entware
- Check script for duplicates
- Launch Entware scripts only after time sync. Waits 120s with 0.5s checking
- Enable swap
- Dismount correctly
- Kill dnscrypt monitoring script because I use entware version
- Gracefully disable Netdata (Entware monitoring packet)
- Check if it was stopped or wait 120s with 0.5s checking to continue scipt
- Kill all logging because it's on /opt partition
- Disable swap
- Unmount partitions
[[ $(pgrep -f -c "`basename \"$0\"`") -gt 1 ]] && echo logger "====== DUP DETECTED: mount ======" && exit
logger "====== USB Mount Start ======"
/sbin/swapon /dev/sda2
logger "====== NTP_READY WAIT ======"
timeout 120 bash -c 'while [ $(nvram get ntp_ready) = 0 ]; do sleep 0.5; done'
logger "====== NTP_READY FINISH ======"
/opt/etc/init.d/rc.unslung start
#cp -f /opt/root/custom.css /opt/www/ext/
/opt/root/dnscrypt_restart &
logger "====== USB Mount Finish======"[[ $(pgrep -f -c "`basename \"$0\"`") -gt 1 ]] && echo logger "====== DUP DETECTED: unmount ======" && exit
logger "====== USB UNmount Start ======"
killall dnscrypt_restart
/opt/etc/init.d/rc.unslung stop
#Graceful netdata shutdown
logger "====== Netdata Shutdown Wait ======"
/opt/bin/timeout 120 bash -c 'while [ -n "$(pidof netdata && true)" ]; do sleep 0.5; done'
logger "====== Netdata Shutdown Finish ======"
killall -15 syslogd
killall -15 klogd
sleep 3
swapoff -a
umount /tmp/mnt/LOGS
umount /opt
logger "====== USB UNmount Finish ======"