[arch-general] systemd start a daemon after the Internet connection is established
Hi, 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. Regards.
On 8 September 2013 18:37, Bill Sun <cap.sensitive@gmail.com> wrote:
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.
Regards.
Try network-online.target instead of network.target.
On Sun, Sep 08, 2013 at 07:27:34PM +0200, Lukas Jirkovsky wrote:
On 8 September 2013 18:37, Bill Sun <cap.sensitive@gmail.com> wrote:
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.
Regards.
Try network-online.target instead of network.target. No. It still doesn't work. I don't use NetworkManger, so my assumption is that the network-online.target does not exist at all. (Seems that `systemctl list-units` confirms that.)
I use dhcpcd@%i to get an ip address from my router. Though the dhcpcd does start before my proxy daemon, the proxy daemon fails before the dhcpcd get an address. So how to write another systemd unit to make sure the Internet connect is established? (maybe a bash script with ping, then checking the exit code? But how to write that systemd unit?) Regards.
On Mon, Sep 16, 2013 at 9:50 AM, Bill Sun <cap.sensitive@gmail.com> wrote:
On Sun, Sep 08, 2013 at 07:27:34PM +0200, Lukas Jirkovsky wrote:
On 8 September 2013 18:37, Bill Sun <cap.sensitive@gmail.com> wrote:
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.
Regards.
Try network-online.target instead of network.target. No. It still doesn't work. I don't use NetworkManger, so my assumption is that the network-online.target does not exist at all. (Seems that `systemctl list-units` confirms that.)
I use dhcpcd@%i to get an ip address from my router. Though the dhcpcd does start before my proxy daemon, the proxy daemon fails before the dhcpcd get an address.
That is weird... dhcpcd@.service has the following lines: Type=forking ExecStart=/usr/sbin/dhcpcd -q -w %I
The -w option to the daemon (--waitip) is there so that it will not fork to the background until an IP is available. And the systemd unit is of type *forking*, so it will not be *started* until it has forked. So, if your proxy has an "After=" relation to dhcpcd@eth0.service, then it should not be started without an IP address. Are you sure it so? You can check whether that's the case: $ systemctl show myproxy.service | grep After= -- Rodrigo
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.
I don't use NetworkManger, so my assumption is that the network-online.target does not exist at all. (Seems that `systemctl list-units` confirms that.)
Try wrapping /srv/proxy/aproxy/bin/main with a script that performs a ping and runs `main` when the connection is established. Systemd allows you to override the configuration.[1] If the unit file you pasted is provided by the package, it surely exists in /usr/lib/systemd/system/aproxy.service. Just create /etc/systemd/system/aproxy.service and override ExecStart. This post may be helpful.[2] [1] http://lists.freedesktop.org/archives/systemd-devel/2013-March/009496.html [2] https://bbs.archlinux.org/viewtopic.php?pid=1192998#p1192998 -- Kind regards, Damian Nowak StratusHost www.AtlasHost.eu
participants (4)
-
Bill Sun
-
Lukas Jirkovsky
-
Nowaker
-
Rodrigo Rivas