troglobit / finit

Fast init for Linux. Cookies included
https://troglobit.com/projects/finit/
MIT License
633 stars 63 forks source link

Network Interfaces and DHCP #164

Closed AwlsomeAlex closed 3 years ago

AwlsomeAlex commented 3 years ago

Hey there again. I'm trying to get networking working with finit. It's a crude form at the moment because I depend on udhcpc and whatever BusyBox gives me. The issue is when I try to add a dhcp service called udhcpc.conf with task [S12345] log <net/eth0/exist> udhcpc -q -n -i eth0 -s /etc/network/rc.udhcp -- DHCP Client it takes about ten seconds for the login prompt to appear and for 'Networking' to start. It also outputs the DHCP requests to the console. If I try to make this a service, it loads faster, but clogs up the console, with it looping in restarting mode. The /etc/network/interfaces entry is: iface eth0 inet dhcp.

I have a workaround where DHCP is done in /etc/network/interfaces. It loads up networking instantly, with no clutter to the console: iface eth0 inet manual pre-up /bin/ip link set eth0 up pre-up /bin/udhcpc -q -n -i eth0 -s /etc/network/rc.udhcp

I was wondering is there a more conventional way of doing this via an finit service? Thanks again!

troglobit commented 3 years ago

For simpler systems I recommend using /etc/network/interfaces, which BusyBox supports. Finit calls ifup -a in the background when it finds that file. We use that approach for $DAYJOB in our NetBox project (a close buildroot derivative).

Another way to do it, similar to what you've done, which we use in our premier product is:

service name:udhcpc :vlan1 [2345] <!net/vlan1/up> udhcpc -f -S -V "Product v9.99" -t 8 -T 5 -A 10 -R -p /var/run/udhcpc-vlan1.pid -i vlan1 -x hostname:foo -o -O 1 -O 3 -O 6 -O 7 -O 12 -O 15 -O 42 -O 121 -a -- DHCP client (vlan1)

We ahve an udhcpc.script which emits all state changes to syslog using the logger tool. In our setup we use the logger from my sysklogd project.

I'm not sure why your task stanza exhibits those issues, it should work. Except for starting it in runlevel S, I'd also recommend removing runlevel 1, since it's usually single-user/recovery mode w/o networking, but that's up to you. I'll have to look into that bit during my Easter break :)

troglobit commented 3 years ago

Sometimes even I have to read the docs. This one isn't that obvious, run/task run until completion. For runlevel 'S' we wait until all run/task have run once to completion. In the case of udhcpc you have to make sure it backgrounds, or run it as a service as in my example.

Hope you get it working. Cheers!