Running init script, hostapd_cli doesn't run and can't reboot device


I am running a custom init script. I put it in /etc/init.d/, made it executable and enabled it.

#!/bin/sh /etc/rc.common


start() {
    /usr/sbin/hostapd_cli -i wlan0-1 -a /bin/hostapd_event -B
    /usr/sbin/hostapd_cli -i wlan1 -a /bin/hostapd_event -B
    sh /bin/hostapd_rssi_disconnect

stop() {
    wlan0_1=$(pgrep -f "hostapd_cli -i wlan0-1 -a /bin/hostapd_event")
    wlan1=$(pgrep -f "hostapd_cli -i wlan1 -a /bin/hostapd_event")
    disc=$(pgrep -f "hostapd_rssi_disconnect")
    kill -2 "$wlan0_1"
    kill -2 "$wlan1"
    kill -2 "$disc"

The script runs, but

  1. hostapd_cli instances do not run
  2. only hostapd_rssi_disconnect runs.
  3. can not reboot until I manually kill hostapd_rssi_disconnect process.

hostapd_rssi_disconnect just collects rssi of connected clients every 5 second. So there is an infinite while loop with sleep 5

###I have the same problem even when I put

/usr/sbin/hostapd_cli -i wlan0-1 -a /bin/hostapd_event -B
/usr/sbin/hostapd_cli -i wlan1 -a /bin/hostapd_event -B

directly into /etc/rc.local file.


I guess that you need to detach at least the desk process with & so that it gets backgrounded and the main script can exit. Otherwise your loop keeps running and this main script does not complete and exit.

Additionally, startup priorities are evaluated alphabetically. 100 equals 10 in practice. You want 99. Otherwise you run much too early.

See similar discussion in e.g. Auto startup apps in /etc/rc.local not loading

I also wonder that you use hostapd_cli instead of hostapd. hostapd_cli is usually used for interacting with already running hostapd. So I am not quite sure what you are trying to do here. Add a trigger for something?


adding & solved the issue of reboot. So the script is running in the background.

But the hostapd_cli is still not running.

Yes I am trying to add a trigger (call script) when an event occurs in hostapd.

Do the hostapdcli sommand work from console? And from a manually launched script?

If yes, then you are probably running this init script before normal hostapd has fully started.

@hnyman yeah hostapd_cli command runs fine when I manually launch it.

Also works when I run that command via a script file. I can see hostapd_cli instances with ps

So maybe I am trying to run before hostapd has started. How do I launch after it starts?

Did you already change the priority to 99?

If that doesn't help, you could add a "sleep 10" command to the init script, so that it waits a few second before running the hostapd

@hnyman yeah I already changed it to 99. I'll try the sleep 10.

@hnyman sleep 10 works! Thank you :slight_smile:
Is there any other way without sleep? Just curious.

If you google similar topics here and in Openwrt forum, you will notice that there is no universal better cure. Some services have rather long internal init times, so there is no guarantee that the previous service is already available.

You can see the long init time of hostapd also in the system log. It takes rather long, before the wifi interfaces are ready.

Ok. got it. It's work pretty well now. So I am happy :slight_smile:


I'm also trying to use hostapd_cli to call a script when a event occurs. I have two wi-fi interfaces and would like the demon to report on both. I notice you use -i wlan0-1 did this make the demon report on both wlan0 and wlan1?

I can't get this to work :frowning: