ZebMcKayhan
Very Senior Member
Hello,
I'm trying to create a script that restores ipsets after reboot. As this have been troublesome before with consecutive runs on boot, I've used a technique with lock file creation from @eibgrad so consecutive executions are run sequentially. This works great as far as I have tested. I've also added a retry every second to wait maximum 30 sec for the usb drive to mount.
Everything is working and my ipsets gets restored every boot.
For reference, here is the script:
but in my syslog, I dont get all messages. I can see nat-start executed before ntp is synced but then klogd is exited and after that there are no syslog messages from the initial run that restored my ipsets.
If I destroy my ipsets and run nat-start manually all syslog messages shows as they should.
This is my syslog relevant parts from boot:
Even tough there are no syslog messages that nat-start completed all ipsets are restored, cron job created and lock file removed so it must have completed.
Is this caused by klogd exited? Or with time sync? Are there any way around it?
I'm running scribe if that could affect this.
Regards
Zeb
I'm trying to create a script that restores ipsets after reboot. As this have been troublesome before with consecutive runs on boot, I've used a technique with lock file creation from @eibgrad so consecutive executions are run sequentially. This works great as far as I have tested. I've also added a retry every second to wait maximum 30 sec for the usb drive to mount.
Everything is working and my ipsets gets restored every boot.
For reference, here is the script:
Code:
#!/bin/sh
############################################################
# required for serialization when reentry is possible
LOCK="/tmp/$(basename $0).lock"
# acquire_lock # one instance at a time
while ! mkdir $LOCK &>/dev/null; do sleep 2; done;
logger -t $(basename $0) "Started"
############################################################
##
## Put existing nat-start directives here
##
IPSET_LIST="NETFLIX-DNS NETFLIX-DNS6 wg11-mac" #List of ipsets to restore
DIR="/opt/tmp" #directory for store ipset
MAX_TRIES=30 #Retries every second [MAX_TRIES] amount of times.
## Normally nothing need to be changed below ##
TRIES="0"
while [ "$TRIES" -lt "$MAX_TRIES" ]; do # Wait for target (usb drive) ready
if [ -d "$DIR" ]; then # target ready?
for IPSET_NAME in $IPSET_LIST; do # Each ipset in list
if [ "$(ipset list -n "$IPSET_NAME" 2>/dev/null)" != "$IPSET_NAME" ]; then #if ipset does not already exist
if [ -s "$DIR/$IPSET_NAME" ]; then #if a backup file exists
ipset restore -! <"$DIR/$IPSET_NAME" #restore ipset
cru a "$IPSET_NAME" "0 2 * * * ipset save $IPSET_NAME > $DIR/$IPSET_NAME" >/dev/null 2>&1 # create cron job for autosave
logger -t $(basename $0) "IPSET restored: $IPSET_NAME"
else
logger -t $(basename $0) "Warning: Failed to find IPSET restore file: $IPSET_NAME"
fi
fi
done
break
else
sleep 1
TRIES=$((TRIES + 1))
if [ "$TRIES" -eq "$MAX_TRIES" ]; then
logger -t $(basename $0) "Warning: Failed to detect mounted USB-Drive within $MAX_TRIES seconds! IPSET not restored!"
fi
fi
done
############################################################
# exit (any concurrent instance(s) may now run)
rmdir $LOCK &>/dev/null;
logger -t $(basename $0) "Completed [$@]"
but in my syslog, I dont get all messages. I can see nat-start executed before ntp is synced but then klogd is exited and after that there are no syslog messages from the initial run that restored my ipsets.
If I destroy my ipsets and run nat-start manually all syslog messages shows as they should.
This is my syslog relevant parts from boot:
Code:
May 5 07:05:20 custom_script: Running /jffs/scripts/nat-start
May 5 07:05:20 nat-start: Started
<snip>
May 5 07:05:21 ntpd: Started ntpd
Oct 15 00:43:39 ntpd: Initial clock set
<snip>
Oct 15 00:43:43 custom_script: Running /jffs/scripts/post-mount (args: /tmp/mnt/UsbDrv)
Oct 15 00:43:43 Diversion: Starting Entware and Diversion services on /tmp/mnt/UsbDrv
Oct 15 00:43:44 kernel: klogd: exiting
Oct 15 00:43:44 RT-AC86U-D7D8 kernel: ip_set: protocol 6
Oct 15 00:43:44 RT-AC86U-D7D8 rc_service: service 3421:notify_rc restart_dnsmasq
Oct 15 00:43:44 RT-AC86U-D7D8 rc_service: waitting "restart_dnsmasq" via ...
Oct 15 00:43:45 RT-AC86U-D7D8 rc_service: udhcpc_wan 2445:notify_rc stop_samba
Oct 15 00:43:45 RT-AC86U-D7D8 rc_service: waitting "restart_dnsmasq" via ...
<snip>
Even tough there are no syslog messages that nat-start completed all ipsets are restored, cron job created and lock file removed so it must have completed.
Is this caused by klogd exited? Or with time sync? Are there any way around it?
I'm running scribe if that could affect this.
Regards
Zeb
Last edited: