magnific0 / wondershaper

Command-line utility for limiting an adapter's bandwidth
GNU General Public License v2.0
1.71k stars 256 forks source link

Persistent usage after reboot not working (solved/workaround) #51

Open ghost opened 4 years ago

ghost commented 4 years ago

I have had issues with Wondershaper not working after reboot and after beating my head against the wall for some time now i have finally solved it, or at least a workaround for the issue. Its in the wondershaper.service file. In my case the problem was as follows:

systemctl status wondershaper returned green bandwidth was not limited systemctl restart wondershaper OR wondershaper -a 'device' -d 'speed' -u 'speed' both worked and limited bandwidth

This ensured that all the code was ok. I figured it had to do with the dependancy network.target but adding Requires=, BindsTo=, Requisite= did nothing.

Finally i added a sleeptimer to a new line, ExecStartPre and finally it works on boot. I think the issue is that with a fast computer and a fast disk it simply boots too fast.

New working wondershaper.service with sleeptimer 10seconds:

/etc/systemd/system/wondershaper.service

[Unit]
Description=Bandwidth shaper/Network rate limiter
Wants=network.target
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/systemd/wondershaper.conf
ExecStartPre=/bin/sleep 10
ExecStart=/usr/sbin/wondershaper -a $IFACE -d $DSPEED -u $USPEED
ExecStop=/usr/sbin/wondershaper -c -a $IFACE

[Install]
WantedBy=multi-user.target

This is more of a workaround than a fix but if it works it works.

Jeronimo17 commented 3 years ago

It also happens to me, and when I suspend the computer and return, the rule does not apply either so the configuration is lost when the interface is restarted

Jeronimo17 commented 3 years ago

For me the best solution has been to put in /etc/network/if-up.d/ a wondershaper script file. With execution permissions and content

#! / bin / sh

wondershaper -a enp6s5 -c
wondershaper -a enp6s5 -d 76800 -u 76800

Example to limit to ~ 70/70 Mb / s

and delete wondershaper.service.

This is how it works for me 100% of the time

ou-li commented 3 years ago

Similar issue here, Ubuntu 18.04, version 1.4.1 "systemctl restart" or sleeptimer do not resolve the problem.

@Jeronimo17's script works, however.

Is there some way to increase verbosity in wondershaper and narrow down where the service silently fails?

magnific0 commented 3 years ago

@fridge-art @Jeronimo17 @ou-li thanks for reporting and documenting the issue. I have read on the issue and it seems the systemd service could still work, by modifying the [unit] section with

After=network-online.target
Wants=network-online.target

This will ensure that all configured network devices are up and have an IP address assigned before the service is started. network-online.target will time out after 90s. Enabling this might considerably delay your boot even if the timeout is not reached.

according to https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

Can anyone of you try this and report whether this also solves the problem? I'd be happy to update the code.

gwarser commented 3 years ago

I tried it without success. But maybe my config is somehow unusual.


OK, looks like I broke something with configuration. Will try again.


Cleaned everything and reinstalled wondershaper - trick with sleep is working target-online is not. I think it's because I disabled "wait-online" services - they caused minute-long delays on startup. I don't know which one I disabled :/ Will need to check logs.

gwarser commented 3 years ago

Nothing in the logs, they go back only 3 months :/

But looks like it started working after enabling every *-online.service - network manager, network and systemd.

My solution will be "sleep" however - I see delays on startup again.

ghost commented 3 years ago

@magnific0 I tried your fix on a fresh install of Manjaro tonight and for me it didnt work. Had to use my fix from OP to get it to be persistent. Still same hardware as when i first posted about this, last time it was Ubuntu and now Manjaro, shouldnt matter though