
Tengo un script que convertí en un servicio systemd de una sola vez. Esto se ejecuta en una raspberry pi y el punto es que si no puede conectarse a Internet, reconfigura el adaptador wifi (?) para crear una red ad hoc y se reinicia.
El problema que tengo es que cuando comprueba aún no ha recibido una dirección IP y por eso piensa que no puede conectarse.
Intenté usar el After=
parámetro to be network-online.target
pero eso no cambió nada e intenté introducir un sleep
comando en el script, pero nuevamente no hubo cambios.
¿Algunas ideas?
Este es el guión check_connection.sh
:
INTERFACE_NAME=$(iwconfig 2>/dev/null | grep -o "^\w*")
sleep 5;
if ifconfig $INTERFACE_NAME | grep -q "inet addr"
then
echo 'connected'
# if connected check if it's ad hoc mode or not
if iwconfig $INTERFACE_NAME | grep -q "Mode:Ad-Hoc"
then
echo 'start dhcp server'
# if running in ad hoc mode make sure server starts
sudo service isc-dhcp-server start
fi
else
echo 'not connected'
# if not connected switch settings to ad hoc and reboot
sudo cp /etc/network/interfaces-adhoc /etc/network/interfaces
sudo reboot
fi
/etc/systemd/system/check_connection.service:
[Unit]
Description=Check whether connected at startup
After=network-online.target
[Service]
User=root
ExecStart=/bin/bash /home/pi/check_connection.sh
[Install]
WantedBy=multi-user.target
EDITAR
El sistema operativo que estoy ejecutando es:Linux raspberrypi 4.1.7+ #817 PREEMPT Sat Sep 19 15:25:36 BST 2015 armv6l GNU/Linux
Respuesta1
Una de las soluciones sería actualizar el ifupdown
paquete a una versión superior (>= 0.8.9) utilizando los backports de Debian (yopensaresto debería funcionar en raspberian), eche un vistazo ahttps://backports.debian.org/Instructions/. Luego necesita actualizar el ifupdown
paquete.
Lo que sucede aquí es que network-online.target
no está ejecutando ningún servicio y esto significa que se considera "iniciado" sin esperar nada. La versión más reciente del ifupdown
archivo networking.service
contiene las siguientes líneas, lo que significa que hará que network-online.target
espere hasta que se inicie por completo:
[Install]
WantedBy=multi-user.target
WantedBy=network-online.target
EDITAR: Otra opción podría ser usar en After=networking.service
su lugar