I have a desktop running Ubuntu Gnome 16.04. On reboot, sometimes (randomly) the network card disappears. That is,
eth0 disappears from
lspci, etc. I cannot bring back
eth0 without a reboot in such situations. Natually, the machine is not connected to the Internet when this happens. Also, usually, a single reboot fixes the problem and the ethernet shows up again.
I don't have a clue about how I can start to debug this. However, I would like to have a script or service that checks if the ethernet was loaded (computer is connected to the Internet), and reboots if not. This script or service should run before any user logs in, because, sometimes I restart the machine remotely, and lose access to it if ethernet does not come up.
I have a script that checks if the Internet is connected. But I have been unsuccessful in getting it to run at the correct time. I have tried using
cron seems to be initialized before internet connects, (as the log file records); I tried placing an upstart script in
/etc/init/, only to realize that Ubuntu now uses
systemd and upstart is not recommended anymore. I also wrote a
systemd unit file, and had mixed results (bootloop and nothing). What am I doing wrong?
Internet connectivity test script
#!/bin/bash ping -c 1 220.127.116.11 > /dev/null if [ $? -eq 0 ]; then echo "ok" else reboot fi
systemd unit file that caused bootloop
[Unit] Description=Tests Internet connectivity. Reboots if not connected. After=network.target syslog.target [Service] Type=forking ExecStart=/usr/local/bin/internet_test.sh StandardOutput=syslog StandardError=syslog SyslogIdentifier=InternetTest [Install] WantedBy=multi-user.target
systemd unit file that did nothing (even the service did not log as started)
[Unit] Description=Tests Internet connectivity. Reboots if not connected. After=multi-user.target [Service] Type=forking ExecStart=/usr/local/bin/internet_test.sh StandardOutput=syslog StandardError=syslog SyslogIdentifier=InternetTest