User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

How to start hostap, dhcpcd, isc-dhcpd-server [SOLVED]

Sun Jan 08, 2017 4:15 pm

Hi,

I've set up my RasPi model 3 with wlan0 to connect to an upstream router, and wlan1 to offer connectivity to downstream IP nodes. I'm configuring the static IPv4 addresses for the downstream wlan1 through dhcpcd.conf (and not /etc/network/interfaces). I have installed: hostap(d), dhcpcd (upstream dynamic and downstream static IP configuration), and finally ISC dhcpcd server.

Unfortunately, systemd in Raspbian Jessie aggressively starts hostapd, dhcpcd, and isc-dhcpd-server in parallel -- which is a really bad idea. More often than not, at least the ISC dhcpd fails because dhcpcd hasn't yet configured the downstream interface with the static IPv4 address. Sometimes, even dhcpcd trips over its own feet when it gets ahead of hostapd.

So my question is: how do I tell systemd to start these three daemons in a specific order, and only one after the other, but not in parallel?
Last edited by elkberry on Tue Jan 10, 2017 12:59 pm, edited 2 times in total.
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

david reeves
Posts: 11
Joined: Thu Nov 26, 2015 10:58 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Sun Jan 08, 2017 5:08 pm

It looks like you are having a similar issue to what I'm fighting.

viewtopic.php?f=36&t=170666

I believe that dhcpcpd and isc-dhcpd conflict and only one should be used...so I uninstalled (apt-get remove) isc-dhcpd that I was using previously. Maybe that will help you. Alternately you might be able to sudo systemctl disable dhcpcd.

You might look into /etc/rc.local to control the start sequence. You can look at mine although I'm having issues too so no warranty but maybe it's a starting point. It seems this shell script can control the starting sequence of the services.

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Sun Jan 08, 2017 5:19 pm

David,

there is no conflict, as I'm running dhcpcd (the client) on the upstream wlan0 interface. And isc-dhcp-server is running solely on the downstream wlan1 interface. In my setup, wlan0 is in managed mode, as it connects to an upstream AP. In contrast, wlan1 is the downstream AP. There's no problem with that, but more often than I like, the (undefined) starting order causes problems with isc-dhcp-server, as it seems to be especially sensitive to getting started without any interfaces ready for it. So to me, it seems that you are facing a completely different issue. I don't want to deinstall ISC DHCP server, as I need it on the downstream interface to serve legacy IPv4 devices.
Last edited by elkberry on Sun Jan 08, 2017 5:48 pm, edited 1 time in total.
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

david reeves
Posts: 11
Joined: Thu Nov 26, 2015 10:58 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Sun Jan 08, 2017 5:28 pm

I forgot to add that you may need to do the below before controlling the start in /etc/rc.local

sudo update-rc.d dhcpcpd remove
sudo update-rc.d isc-dhcp-server remove

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Sun Jan 08, 2017 5:52 pm

David,

erm, I'm on Raspbian Jessie and that is using the systemd-based initialization. I've seen that the ISC DHCP server gets a generated unit service description, but dhcpcd has its dedicated unit service description.

So my question is: how do I get the order right? Either I did the usual after= wrong or there is more to watch for, and that's I'm asking for.
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

hortimech
Posts: 345
Joined: Wed Apr 08, 2015 5:52 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Mon Jan 09, 2017 9:27 am

If you look very carefully, you will find that you have isc-dhcp-client and dhcpcd running, you don't need both. I just 'apt-get purge dhcpcd5' then set up the fixed ip's on the clients. This gets you back to how wheezy used to do things.

User avatar
procount
Posts: 1897
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Mon Jan 09, 2017 10:38 am

I noticed when I previously created my AP by executing all of these services sequentially from a script, that even though they are started manually in the right order, I still needed to insert delays into the script in order for it to start up properly each time. So I'm guessing that even though a service is reported to have started correctly, it may not be quite ready for the next one to use it. Maybe it has some additional setup that it is deferring to its daemon? So maybe try wrapping each service in a script and adding a small delay at the beginning of each one? (Just my twopenneth worth....)
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Mon Jan 09, 2017 5:01 pm

hortimech wrote:If you look very carefully, you will find that you have isc-dhcp-client and dhcpcd running, you don't need both. I just 'apt-get purge dhcpcd5' then set up the fixed ip's on the clients. This gets you back to how wheezy used to do things.
And if you read very carefully then you'll notice that I wrote about syncing ISC DHCP server downstream with the upstream DHCP client. Is that really that difficult to see?
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Mon Jan 09, 2017 5:09 pm

procount wrote:So I'm guessing that even though a service is reported to have started correctly, it may not be quite ready for the next one to use it. Maybe it has some additional setup that it is deferring to its daemon? So maybe try wrapping each service in a script and adding a small delay at the beginning of each one? (Just my twopenneth worth....)
Yes, that reflects my impression too: to init or systemd, the service is started, so its dependent services can be started next, when in fact the service has just daemonized, but isn't yet ready for prime time.

I've tried a different approach this morning by hooking into dhcpcd's STATIC reason: I then (try to) start or restart the ISC DHCP server. However, this isn't reliable either, for reasons I don't understand yet. When I dump the interface configuration using "ip addr show dev wlan1" I can see that the interface is already properly configured, so that part is correct. However, systemd does sometime not even attempt to start the server service, as I can deduce from the logs: there is no LSB blabla starting message.

Is there some kind of dead window within which systemd refrains from starting a service after it may have terminated earlier? A sleep before the systemctl start also doesn't ensure proper restart either...
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

User avatar
procount
Posts: 1897
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Mon Jan 09, 2017 5:21 pm

Just thinking out loud: If you could identify some externally visible aspect of the previous service that is required by the next service (e.g. valid IP address), maybe you could write an intermediate service or target that only completes when that aspect is available? Then you could insert that in your systemd chain of dependencies instead of a sleep(). It might help with the restarts. (Dunno if it is feasible as I'm still learning about systemd myself)
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Mon Jan 09, 2017 5:38 pm

procount wrote:Just thinking out loud: If you could identify some externally visible aspect of the previous service that is required by the next service (e.g. valid IP address), maybe you could write an intermediate service or target that only completes when that aspect is available? Then you could insert that in your systemd chain of dependencies instead of a sleep(). It might help with the restarts. (Dunno if it is feasible as I'm still learning about systemd myself)
That's a really good idea. And I'm stuck in the same mud as you as to how to realize it. But this is something I can try to find out on a larger timescale.
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Mon Jan 09, 2017 5:49 pm

I've followed another idea with (some?) success so far: automatic restart of the ISC DHCP server service.

For this, first copy the generated isc-dhcp-server.service unit description to its system place, where we can then make the modifications:

Code: Select all

sudo cp /run/systemd/generator.late/isc-dhcp-server.service /etc/systemd/system/
Next, modify this unit description as follows: under the [Service] heading, change the Restart= setting, and add a RestartSec= setting to restart after 5 seconds:

Code: Select all

[Service]
Restart=on-failure
RestartSec=5
Then add an [Install] section to the end of the unit description:

Code: Select all

[Install]
WantedBy=multi-user.target
A couple of restarts later, my Raspberry Pi now always comes up correctly with the ISC DHCP server running. Either it is fooling me quite heavily or this seems to be an improvment.

Make sure to reinstall the service by executing:

Code: Select all

sudo systemctl daemon-reload
sudo systemctl enable isc-dhcp-server.service
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

User avatar
procount
Posts: 1897
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Raspbian Jessie: How to start hostap, dhcpcd, isc-dhcpd-

Mon Jan 09, 2017 10:54 pm

That might be a solution to a similar problem I have..... must give it a go.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

Return to “Networking and servers”