Question

I have a web proxy that can only initiate itself online, otherwise it would exit with an error. To daemonize that proxy, I wrote the following systemd service file:

[Unit]
Description=A Proxy Server
After=network.target

[Service]
Type=simple
ExecStart=/srv/proxy/aproxy/bin/main

[Install]
WantedBy=multi-user.target

When the server is connected to the Internet, this service file can launch the proxy successfully, but it doesn't work on system startup, supposedly due to the lack of an connection with Internet access. So I need systemd to make sure the connect has been established before it launch this daemon.

Was it helpful?

Solution

Add an ExecStartPre statement to your service that calls a script that will not complete until the network is up to your satisfaction.

Depending on your configuration and needs you could loop until pinging an internet host is successful or check that your interface has a valid IP for your network. If having a physical connection is good enough for your needs have your script check the status of /sys/class/net//operstate.

You could also call such a script in it's own unit file and add it to the After statement in your service file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top