Acceptable way to autoconnect eth0 as well as wlan0?

I was trying to have both eth0 as well as wlan0 to autoconnect on boot but struggled a bit to find a solution. I tried rc.local but it did not work reliably and felt somewhat wrong.

So I wrote a little service to handle this but wonder if this really is the way to go:

What you need is the output of connmanctl services for your wifi. So connect to your wifi via “My OSMC” and run the command in a shell afterwards, copy & paste the WIFI-ID (a string like wifi_xxxxxxxxxx_xxxxxxxxxx_managed_psk) of your wifi to a local editor.

Run sudo nano /etc/systemd/system/wifi.service and paste the following content:

Description=Connect Wifi interface

ExecStart=/bin/sh -c "sleep 10;/usr/bin/connmanctl connect [WIFI-ID]"
ExecStop=/bin/sh -c "/usr/bin/connmanctl disconnect [WIFI-ID]"


Remember to replace [WIFI-ID] with the relevant output of connmanctl services and save the file.

Issue sudo chmod 777 /etc/systemd/system/wifi.service and finally enable the service via systemctl enable wifi.service.

Reboot your device (sudo reboot), wait for it to fully boot up and check if it was successful by running systemctl status wifi.service and connmanctl technologies to find out if wifi is connected.

Any possible improvements or better solutions? Any chance to get rid of the sleep 10 within the service?

I think you can just set PreferredTechnologies=wifi,ethernet.

Will check if that actually works tonight, thanks Sam!

Works - better solution than mine :wink:

@dbmandrake: Thoughts on making this the default? It definitely needs some testing.