You are not logged in.
Not using NetworkManager - base Arch Linux with standard netcfg
The situation (coming from an old SysV-init guy who's pretty new to systemd):
I have an application that has a dependency on a specific interface alias. To be more specific:
1) eth0 comes up as a DHCP interface (but the address is static on the DHCP server side) and assigns the base IP, which we'll call 192.168.1.2
2) network.target is satisfied since the interface is up
3a) netcfg POST_UP executes on the interface, assigning IP address 192.168.1.3 with label eth0:0 to eth0
3b) The application service (with an After of network.target) starts, attempting to bind a port listener on address 192.168.1.3
Therein lies the rub. 3a and 3b happen in parallel, creating a race condition. If the alias happens to be assigned before the application starts, all is well. If the application initializes before the alias, it dies an ugly death, failing to bind to a non-existent address. It's a coin toss which one "wins".
My solution thus far has been to add a ExecStartPre stanza to the application's service calling "/usr/bin/sleep 5", pretty much guaranteeing that the alias will be defined before the application's ExecStart. This is so ugly and inelegant it's embarassing.
Two questions:
- Is there a cleaner way to approach this - perhaps some way to indicate to systemd that eth0:0 must exist prior to starting the application (along the lines of a mythical AfterInterface element
? I'd considered creating a 0-byte file in /tmp in POST_UP and having my application service check for existence, but it seems that if it doesn't exist, systemd will just skip launching the service, not delay its launch. I cannot create the alias as part of ExecStartPre for the application, since this interface alias is actually used by multiple applications/services.
- Would migrating to netctl alleviate this at all (to be more specific, does netctl have a more coherent definition of interface aliasing than hand-creating them via POST_UP, and if so, are the aliases defined by netctl prior to satisfying network.target)?
Thanks much for any insight,
Rodney
Last edited by rhester72 (2013-05-03 16:46:47)
Offline
Can't you just create a service to accomplish 3a, and configure 3b with "After=<3a>"?
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
I can...but my understanding of why the AL wiki recommends assigning aliases in POST_UP is to ensure they are consistently assigned if the interface should be brought offline and back online. I'm not sure if this is an issue in practice, however - since the same contention would exist on the simplest-possible construct (i.e. what happens to all the services that have network listeners if eth0 just goes away for a while and comes back?).
Rodney
Offline
Switched to netctl and it does exactly what I was looking for (including simple and proper interface aliasing), though your solution was of course valid.
Thanks!
Rodney
Offline
Glad you fixed it. I have no experience with netctl, but it sounds like it's the better solution! ![]()
Be sure to mark thread solved.
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline