I am using Linux Mint 20.
I am using a vpn with a kill switch (protonvpn-cli ks --on
).
So, if the vpn connection drops for some reason, the network get disconnected.
When the network get disconnected, my youtube-dl
download stops permanently with the error
ERROR: Unable to download JSON metadata: <urlopen error [Errno -2] Name or service not known> (caused by URLError(gaierror(-2, 'Name or service not known')))
The issue is, I want youtube-dl
to pause instead of closing, and resume when the connection is back.
I checked Retry when connection disconnect not working but I do not think it is relevant to my problem.
My config file looks like
--abort-on-error
--no-warnings
--console-title
--batch-file='batch-file.txt'
--socket-timeout 10
--retries 10
--continue
--fragment-retries 10
As I use batch files, I do not want to start the process from the beginning. I just want to pause the youtube-dl
process till I get connected again and then continue the process.
How can I do that?
Update 1:
So far, what I have found is, to pause a process we can do something like:
$ kill -STOP 16143
To resume a process we can do something like:
$ kill -CONT 16143
I am not sure but think that we can know if my network is up or not by pinging1 2:
#!/bin/bash
HOSTS="cyberciti.biz theos.in router"
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)"
fi
done
However, it does not seem like an efficient solution.
Linux: execute a command when network connection is restored suggested using ifplugd
or using /etc/network/if-up.d/
.
There is another question and a blog post which mention using /etc/NetworkManager/dispatcher.d
.
As I am using Linux Mint, I think any solution revolving around NetworkManager will be easier for me.
--socket-timeout 3600
and my download did not stop for a long time now. However, the documentation is not clear and I am not sure what--socket-timeout
actually does. I am not even sure whether (in the mean time) the vpn connection dropped and I got disconnected or not. – Ahmad Ismail Jan 05 '21 at 06:05