You may not have /usr/local/var
created in you system. I am on a sysvinit
-based Linux and that was the reason why my init script
was failing to bootstrap Tor network when each time I started tor with service tor start
Starting Tor...
Feb 09 09:19:25.965 [notice] Tor 0.4.8.10 running on Linux with Libevent 2.1.12-stable, OpenSSL 3.0.11, Zlib 1.2.13, Liblzma N/A, Libzstd N/A and Glibc 2.36 as libc.
Feb 09 09:19:25.965 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
Feb 09 09:19:25.965 [notice] Read configuration file "/usr/local/etc/tor/torrc.sample".
Feb 09 09:19:25.966 [warn] Couldn't find $HOME environment variable while expanding "~/.tor"; defaulting to "".
Feb 09 09:19:25.966 [warn] Default DataDirectory is "~/.tor". This expands to "/.tor", which is probably not what you want. Using "/usr/local/var/tor" instead
Feb 09 09:19:25.966 [notice] Opening Socks listener on 127.0.0.1:9050
Feb 09 09:19:25.966 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9050
Feb 09 09:19:25.966 [warn] Error creating directory /usr/local/var/tor: No such file or directory
Feb 09 09:19:25.966 [notice] Closing partially-constructed Socks listener connection (ready) on 127.0.0.1:9050
Feb 09 09:19:25.966 [warn] Failed to parse/validate config: Couldn't create private data directory "/usr/local/var/tor"
Feb 09 09:19:25.966 [err] Reading config failed--see warnings above.
Starting tor without giving it the configuration file does not help - tor
will default to reasonable defaults:
Starting Tor...
Feb 09 09:56:21.102 [notice] Tor 0.4.8.10 running on Linux with Libevent 2.1.12-stable, OpenSSL 3.0.11, Zlib 1.2.13, Liblzma N/A, Libzstd N/A and Glibc 2.36 as libc.
Feb 09 09:56:21.102 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
Feb 09 09:56:21.102 [warn] Couldn't find $HOME environment variable while expanding "~/.torrc"; defaulting to "".
Feb 09 09:56:21.102 [notice] Configuration file "/usr/local/etc/tor/torrc" not present, using reasonable defaults.
Feb 09 09:56:21.103 [warn] Couldn't find $HOME environment variable while expanding "~/.tor"; defaulting to "".
Feb 09 09:56:21.103 [warn] Default DataDirectory is "~/.tor". This expands to "/.tor", which is probably not what you want. Using "/usr/local/var/tor" instead
Feb 09 09:56:21.103 [notice] Opening Socks listener on 127.0.0.1:9050
Feb 09 09:56:21.103 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9050
Feb 09 09:56:21.103 [warn] Error creating directory /usr/local/var/tor: No such file or directory
Feb 09 09:56:21.103 [notice] Closing partially-constructed Socks listener connection (ready) on 127.0.0.1:9050
Feb 09 09:56:21.103 [warn] Failed to parse/validate config: Couldn't create private data directory "/usr/local/var/tor"
Feb 09 09:56:21.103 [err] Reading config failed--see warnings above.
I got this output when trying to start tor with /etc/init.d/tor
(disabling configuration file with commenting out TOR_OPTIONS
does not resolve the issue:
#!/bin/sh
TOR_BIN=/usr/local/bin/tor
#TOR_OPTIONS="-f /usr/local/etc/tor/torrc.sample" # Specify the path to your torrc file
start() {
echo "Starting Tor..."
"$TOR_BIN" &
#"$TOR_BIN" "$TOR_OPTIONS" &
}
stop() {
echo "Stopping Tor..."
killall tor
}
status() {
if pgrep -x "tor" > /dev/null
then
echo "Tor is running."
else
echo "Tor is not running."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
As of time of the relase 0.4.8.10
, if you want to run tor
as a service in the background, having /usr/local/var/
in your system is a prerequisite. This directory somehow doesn't get created in the process of compiling tor from source. There is a mention and reference to /usr/local/var/
in Makefile
but I have not noticed any mkdir
command creating it.
mkdir -p /usr/local/var/
as root solves the issue.
As an alternative that does not require creating /usr/local/var/
you can manually launch tor in the background with nohup tor>/tmp/tor.log 2>&1 &
.
To view its status you would then have to use tail -n 20 /tmp/tor.log
and killall tor
to stop it.