If by "crontab method" you mean a cron job start @reboot then no, that won't work as cron will run it before the network (by extension teh internet) is available.
There is no reliable way for the system to do this for you. You can get close by using a systemd service with an apropriate dependency and Restart=always but AFAIK while there is a network-online.target there is no "I can reach the internet" target nor is there an "I can reach a specific server on the internet" target.
You need to handle not being able to connect to the desired target (and the network not being available) in your code if you want things to be reliable. If you try to leave it to systemd it will give up after five attempts unless configured otherwise and if configured otherwise will hog a CPU core and flood your logs/journal with messages.
If you try to leave it to cron, you've no chance. Cron doesn't do process management or error recovery - it just runs the command you tell it to at the time you tell it to.
[shameless self promotion]
Running A Program At Start Up A Beginner's Guide, particularly sections 4.4.5.2 and 8.
[/shameless self promotion]
Oh, and please ignore any idiot who tells you that inserting a fixed length sleep at the start of your crontab entry is a suitable fix. Doing so is an ugly hack that does not cover all circumstances.
There is no reliable way for the system to do this for you. You can get close by using a systemd service with an apropriate dependency and Restart=always but AFAIK while there is a network-online.target there is no "I can reach the internet" target nor is there an "I can reach a specific server on the internet" target.
You need to handle not being able to connect to the desired target (and the network not being available) in your code if you want things to be reliable. If you try to leave it to systemd it will give up after five attempts unless configured otherwise and if configured otherwise will hog a CPU core and flood your logs/journal with messages.
If you try to leave it to cron, you've no chance. Cron doesn't do process management or error recovery - it just runs the command you tell it to at the time you tell it to.
[shameless self promotion]
Running A Program At Start Up A Beginner's Guide, particularly sections 4.4.5.2 and 8.
[/shameless self promotion]
Oh, and please ignore any idiot who tells you that inserting a fixed length sleep at the start of your crontab entry is a suitable fix. Doing so is an ugly hack that does not cover all circumstances.
Statistics: Posted by thagrol — Sun Sep 29, 2024 10:56 pm