How do I start a service after the network is up?
Solution 1
You should modify the squid.conf file in /etc/init so that it only starts when network is up:
start on (started networking)
You can find much more info here, and looking at the files in your /etc/init/ dir.
This question should also help. If you prefer to configure it with a GUI, look here.
Solution 2
Here are two examples from the Upstart Cookbook:
To start a job when eth0 is available
start on net-device-up IFACE=eth0
To start once a non-loopback device has come up:
start on net-device-up IFACE!=lo
Note: net-device-up
is not a regular job, it's an "Ubuntu well-known event".
Related videos on Youtube
om123
I'm a software developer living in Switzerland. You can reach me at digulla at hepe dot com.
Updated on September 18, 2022Comments
-
om123 over 1 year
In my case, squid is started before DHCP has written a new
/etc/resolv.conf
which results in odd errors (timeouts, 504 Gateway) when I try to load a page in the web browser.As I see it, the correct solution would be to start squid only after dhcpd/NetworkManager/whoever (?) has finished configuring the network.
-
Javier Rivera about 12 yearsWhich Ubuntu version are you using?. Or more concrete, are you using SysV or upstart?.
-
om123 about 12 yearsI'm on 11.10 and upstart.
-
Javier Rivera about 12 years
-