alfred: workaround race condition when batmanif is not ready at boot time
[lede-routing/.git] / alfred / files / alfred.init
index b678d4c8be74d970f851b0f2f73e7e9b610e46de..b777b535ab3d8587321b614b776543e3d0583d72 100755 (executable)
@@ -16,6 +16,7 @@ pid_file_alfred="/var/run/alfred.pid"
 pid_file_vis="/var/run/batadv-vis.pid"
 enable=0
 vis_enable=0
+batmanif=""
 SERVICE_DAEMONIZE=1
 SERVICE_WRITE_PID=1
 
@@ -23,7 +24,7 @@ alfred_start()
 {
        local args=""
        local section="$1"
-       local disabled interface mode batmanif
+       local disabled interface mode
 
        # check if section is disabled
        config_get_bool disabled "$section" disabled 0
@@ -62,6 +63,21 @@ start()
        if [ "$enable" = "0" ]; then
                exit 0
        fi
+
+       mesh_dir="/sys/class/net/$batmanif/mesh/"
+       if ! [ -d "$mesh_dir" ] ; then
+               timeout=30
+               echo "${initscript}: waiting $timeout secs for $batmanif interface..."
+               for i in $(seq $timeout); do
+                       sleep 1
+                       [ -d "$mesh_dir" ] && break
+                       if [ $i == $timeout ] ; then
+                               echo "${initscript}: $batmanif not detected, alfred not starting."
+                               exit 1
+                       fi
+               done
+       fi
+
        echo "${initscript}: starting alfred"
        SERVICE_PID_FILE="$pid_file_alfred"
        service_start /usr/sbin/alfred ${alfred_args}