Community discussions

MikroTik App
 
eguun
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 82
Joined: Fri Apr 10, 2020 10:18 pm

Function to save some items on disk just before reboot

Wed Apr 14, 2021 9:25 am

Hi,

I am interested to save on disk some items just before reboot: for example the graph data.

I am aware that we can set the graph to be saved at regular intervals. But this doesn't solve it really:
1- either the user sets a short interval (ie: 5 minutes) to secure a minimum data loss between last-save and reboot ... but at the downside of very frequent disk writes
2- or the user sets a longer interval (ie: 24H) but will have much longer data loss, at the upside of fewer data-writes
None of the above are really optimal, this is not the solution I am looking for.


Why am I confident something must exist behind the scenes?

The DHCP leases are preserved upon reboot, even when the DHCP server is specifically instructed not to save them on disk regularly.

Example:
My Mikrotik is configured to NOT store leases on disk: /ip dhcp-server config set store-leases-disk=never
Yet, once rebooted, the leases are being preserved and the DHCP server reports the lease time remaining for each individual lease granted pre-reboot.

Conclusion: at some point a fonction must be invoked just before reboot to write the DHCP leases.

I am interested to invoke this function to save, just before reboot other parameters, such as graph data.
Is there any pointer I can work with?


Kind Regards
 
pe1chl
Forum Guru
Forum Guru
Posts: 10195
Joined: Mon Jun 08, 2015 12:09 pm

Re: Function to save some items on disk just before reboot  [SOLVED]

Wed Apr 14, 2021 11:44 am

There is a function in the scheduler to call a script at "startup" time.
It would probably be a good feature suggestion to add a new "shutdown" time which means that the script will be called just before reboot or shutdown.
Of course it is a bit tricky because the user likely expects that all functionality is still available to the script, so it should be the first thing to run when reboot or shutdown is called and it should be waited to finish before moving on to stopping internal processes, shutting down network interfaces, etc.
However, that also means a reboot or shutdown can take arbitrary amount of time and may never be possible anymore when a script is added that hangs.

So it probably requires quite some consideration and work, and the uses for it are a bit limited.
Instead you can make your own script that does what you like to do and then does the reboot or shutdown in the script, and you call that instead of using reboot directly.
 
eguun
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 82
Joined: Fri Apr 10, 2020 10:18 pm

Re: Function to save some items on disk just before reboot

Wed Apr 14, 2021 1:03 pm

Thanks pe1chl,

Indeed a workaround could be to have a script that is run pre-reboot to handle the following:
- update the graph settings to write on disk every 5 minutes (or any shorter interval)
- wait for at least that interval to secure one cycle of disk write
- reset the graph settings back to the original value
- return back to the reboot script

Thanks

Who is online

Users browsing this forum: EmuAGR, synchro and 71 guests