Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 4238  / 3 Years ago, sat, may 1, 2021, 3:10:21

On a Ubuntu 20.04.2 TLS server, I have a need to start a service after another one has fully started up. Specifically, the openvpn-server service creates a tun0 interface with the IP address 10.87.0.1 to which the rinetd service then binds. So the rinetd service should only be started after the openvpn-server service has created that interface.


rinetd comes with a sysvinit service script /etc/init.d/rinetd saying:


# Required-Start:    $remote_fs $syslog
# Required-Stop: $remote_fs $syslog

This causes rinetd to be started during system startup before openvpn-server has created the interface. It then emits the log message:


rinetd[792]: couldn't bind to address 10.87.0.1 port 873 (Cannot assign requested address)

and does not accept connections until I manually restart it with sudo systemctl restart rinetd, after which it then runs just fine.


According to sudo systemctl status the openvpn server process is run by a systemd service named [email protected].
Extending the Required-Start line in /etc/init.d/rinetd to say:


# Required-Start:    $remote_fs $syslog openvpn-server@server

is duly translated by systemd-sysv-generator to an additional line


[email protected]

in /run/systemd/generator.late/rinetd.service.
But systemd ignores that. rinetd still shows the same log message and malfunction, proving that it is still started before openvpn-server is up.


How can I get systemd to reliably start the rinetd service only after the openvpn-server service has done its part and created the interface?


More From » startup

 Answers
2

If we first take systemd, I think it's better if you address the interface directly. Devices in the dev and sysfs tree are exposed to systemd and can be used to make dependencies to other units.


Start by masking the original startup script.


systemctl mask --now rinetd.service

With an instantiated .service, e.g., [email protected], you can start one or several instances if needed, if we were, to have more than one device (provided rinetd can bind to several interfaces).


[Unit]
Description=Rinetd connection forwarding service (%I)
After=sys-subsystem-net-devices-%i.device
BindsTo=sys-subsystem-net-devices-%i.device

[Service]
Type=forking
ExecStart=/usr/sbin/rinetd
PIDFile=/var/run/rinetd.pid
ExecReload=kill -HUP $MAINPID

[Install]
WantedBy=sys-subsystem-net-devices-%i.device

You can then instantiate the service together with a device name:


systemctl enable --now [email protected]

[#1572] Sunday, May 2, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ampust

Total Points: 133
Total Questions: 109
Total Answers: 111

Location: Reunion
Member since Fri, Jul 22, 2022
2 Years ago
ampust questions
Thu, Jul 15, 21, 16:30, 3 Years ago
Mon, Oct 24, 22, 05:38, 2 Years ago
Thu, Sep 15, 22, 14:37, 2 Years ago
Tue, Sep 7, 21, 17:46, 3 Years ago
;