Sujet : Re: Delaying Autostart
De : theom+news (at) *nospam* chiark.greenend.org.uk (Theo)
Groupes : comp.sys.raspberry-piDate : 03. Jun 2025, 15:32:19
Autres entêtes
Organisation : University of Cambridge, England
Message-ID : <lKm*Ch8dA@news.chiark.greenend.org.uk>
References : 1 2 3 4
User-Agent : tin/1.8.3-20070201 ("Scotasay") (UNIX) (Linux/5.10.0-35-amd64 (x86_64))
Chris Elvidge <
chris@internal.net> wrote:
On 03/06/2025 at 14:00, Oscar wrote:
In article <101itmk$2mr8t$1@dont-email.me>,
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
Instead of waiting for some fixed interval, you could add a prior command
using wget or something to repeatedly try accessing that URL, say at 5
second intervals or whatever, until it becomes accessible, before allowing
the startup to proceed.
For inspiration, I made a script to 'etherwake' a device and wait for it
to get ready using wget in combination with the 'timeout' command. I run
'timeout 1 wget <url>' which returns an error if wget does not respond
in 1 second, or wget returns an error itself. I use this in a while
loop that repeats this until the wget succeeds:
etherwake -D -i ${IFACE} ${MACADDR}
while ! timeout 1 curl --noproxy \* "${URL}" &> /dev/null
do
echo -n .
sleep 1
done
The OP could replace the 'sleep 120' in the other script with this loop.
I was going to suggest something similar like that too. It is worth
checking what the webserver is giving you - some services give a generic
'please wait while I start up' web page which may not be what you want.
Maybe you need to ask for a specific page and count a redirect (to the
'please wait') page as a failure.
Why waste a curl call when ping 8.8.8.8 would work with less overhead?
The purpose is to test a specific service *on this machine* has started up,
not generic internet connectivity.
Theo