Debian: Spurious restarts lead to tor being disabled until next reboot
This is a general
systemd thing, it's explained under "Avoiding the trap: the start limit" in this article: https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6
Sometimes during boot, my network card is doing something funky that leads to tor service(s) being restarted quickly.
In SystemD, there's a mechanism to stop failing services to avoid spamming the log / consuming resources for a service doomed to fail repeatedly, StartLimit. This is governed by the settings
StartLimitBurst= # number of restarts StartLimitIntervalSec= # interval
When a service is restarted more than
StartLimitBurst times within a
StartLimitIntervalSec window, the
tor@.service is stopped, and no further attempts are made to restart it, rendering
tor unusable until next reboot.
This issue can be solved somewhat by setting a
RestartSec= setting to enforce a wait between service restarts, but the StartLimit also includes manual/scripted restarts, so I found the most reliable way to fix the problem (in addition to
RestartSec=10) was to set
StartLimitIntervalSec=0 in the
[Unit] section, turning off the StartLimit mechanism for Tor.