do not restart tor when editing torrc, just reload it
When restart is used? Here
First, prefer tor@default instead of tor, tor call tor@default, if some error appears, it won't be shown on tor, just on tor@default.
Completely remove restarting tor? No, but it should be separate from reloading, prefer reload. From my perspective, you should only restart tor if not making any connections to the network or related.
This will avoid losing connection to a hidden service if it is not replaced in the torrc, so you can reload tor through Tor Browser Ronin UI to recreate Specter tor address as an example and still be good.
4 methods of reloading tor
- pkill (all instances and consequently all controllers)
- tor-prompt (will use the defaults ports if none is specified)
- systemd (specific instance and consequently all controllers inside that instance)
- stem (will use the defaults ports if none is specified)
Which method to use?
It depends on the case to be useful. Using 1 control port per instance, meaning that reloading either one will have the same result for now, but it can very on the objectives.
Is there different reasons to use each method? YES, please read more below.
Day to day use I just type
sudo pkill -sighup tor cause it is
Reload all tor instances
sudo pkill -sighup tor
Reload specific port with 1 command
https://stem.torproject.org/tutorials/down_the_rabbit_hole.html 9051 for tor@default
sudo -u debian-tor tor-prompt --run 'SIGNAL HUP' -i 9051
Reload or restart specific instance with systemd
sudo systemctl reload-or-restart tor@default
With this, can specify the instance, but not the port. It is possible to have multiple ports on the same instance (tor@default). The benefit of this is that it tries to reload at first, but it will (re)start the service if failed, stopped or inactive. Reload specific port with 1 file and can include password
if using HashedPassword in the torrc, we can still use this, but with controller.authenticate() empty
#!/usr/bin/env python3 from stem import Signal from stem.control import Controller with Controller.from_port(port = 9051) as controller: controller.authenticate() controller.signal(Signal.HUP)
Original comment with images https://github.com/rootzoll/raspiblitz/issues/2409#issuecomment-876340098