Re: Triggering action on connection change using hooks
Roy Marples
Sun May 05 14:53:36 2019
On 05/05/2019 15:36, Reto Schneider wrote:
Antyhing *of relevance* that has changed could mean many things - for
example has the hardware address of the default router changed? Are we
running on wireless or wired?
Yes, this is very vague. Bottom line is that I would like to allow the
user (and even more important, the developers and testers) to easily
enforce an update attempt without having to restart the device or
waiting for the 12h polling interval to end.
Assuming one interface you might want to do this then:
cat /etc/dhcpcd.exit-hook
UPDATE_MARKER="/var/db/update/done"
try_update()
{
[ -e "$UPDATE_MARKER" ] && return 0
do_update && touch "$UPDATE_MARKER"
}
if $if_up || [ "$reason" = ROUTERADVERT ]; then
try_update()
elif $if_down; then
rm -f "$UPDATE_MARKER"
fi
So basically on a sucessful update a marker is created.
If dhcpcd thinks an interface is UP, then it will try and run an update
if the marker does not exist. Once the update has run successfuly the
marker will be created to stop another update.
If dhcpcd thinks an interface is DOWN, then it will remove the marker
file to allow a future UP to do an update.
So all the end user has to do is down/up an interface to trigger an update.
Does this solve your issue?
It would likely need to work alongside the cron job and would need
futher work to ensure they don't update at the same time, but you get
the idea.
Roy
Archive administrator: postmaster@marples.name