I completely rewrote the little script from earlier and it's now a proper init script. Place the below code into `/etc/init.d/cake`. Please note that it is not complete as unloading the modules does not work yet. If I figure it out, I'll update this post. Hoping this can be helpful to people, any feedback appreciated!
#!/bin/bash ### BEGIN INIT INFO # Provides: cake # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 1 # Short-Description: Enable CAKE scheduler ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin . /lib/lsb/init-functions TC=/sbin/tc IP=/sbin/ip if [ -r /etc/default/cake ]; then . /etc/default/cake if [ -z "$DNSPEED" -o -z "$UPSPEED" \ -o -z "$DNLIMIT" -o -z "$UPLIMIT" \ -o -z "$IF" ]; then echo "Error: /etc/default/cake is not complete!" exit 5 fi; if [ ! -x $TC -o ! -x $IP ]; then echo "Error: both $TC and $IP must be present and executable!" # exit 5 fi else echo "Error: /etc/default/cake must exist!" exit 5 fi load() { modprobe sch_cake modprobe act_mirred set_limits return $? } unload() { # FIXME: Figure out how to get the modules unloaded again. # https://github.com/dtaht/sch_cake/issues/35 ifconfig ifb4eth0 down ip link del dev ifb4eth0 modprobe -r act_mirred modprobe -r sch_cake return $? } set_limits() { DNLIMIT=$(($DNSPEED/100*$DNLIMIT)) UPLIMIT=$(($UPSPEED/100*$UPLIMIT)) echo -e "\nDownload limit: ${DNLIMIT}kbps\nUpload limit: ${UPLIMIT}kbps" tc qdisc add dev $IF root cake bandwidth ${UPLIMIT}kbit ip link add name ifb4${IF} type ifb tc qdisc del dev $IF ingress tc qdisc del dev $IF handle ffff: ingress tc qdisc del dev ifb4${IF} root tc qdisc add dev ifb4${IF} root cake bandwidth ${DNLIMIT}kbit besteffort ifconfig ifb4${IF} up tc filter add dev $IF parent ffff: protocol all \ prio 10 u32 match u32 0 0 flowid 1:1 action mirred \ egress redirect dev ifb4${IF} return 0 # FIXME: Be more honest here. } case $1 in start) log_daemon_msg "Enabling Cake scheduler" "cake" load log_end_msg $? ;; stop) log_daemon_msg "Disabling Cake scheduler" "cake" unload log_end_msg $? ;; reload) log_daemon_msg "Setting new limits for Cake scheduler" "cake" set_limits log_end_msg $? ;; status) $TC -s qdisc ;; *) echo "Usage: $0 {start|stop|reload|status}" exit 2 ;; esac
The init script requires `/etc/default/cake` to be present. Mine looks like this:
# The interface to be limited IF=eth0 # Kbps values DNSPEED=100000 UPSPEED=7500 # Percentages DNLIMIT=60 # ERLite3 can only manage 60Mbps UPLIMIT=95
@denist: If you're happy with the results, you can make the script run during boot by saying e.g. `ln -s /etc/init.d/cake /etc/rc2.d/S10cake`.