HelloZeroNet / ZeroNet

ZeroNet - Decentralized websites using Bitcoin crypto and BitTorrent network
https://zeronet.io
Other
18.26k stars 2.26k forks source link

[issue] Zeronet ignores tor = always if started through systemd #1387

Open FaySmash opened 6 years ago

FaySmash commented 6 years ago

Step 1: Please describe your environment

Step 2: Describe the problem:

If I start zeronet by a systemd unit on bootup, it doesn't connect to Tor.

Steps to reproduce:

  1. create a zeronet.service file at /lib/systemd/system/
  2. put in this
    
    [Unit]
    Description=Zeronet daemon
    Wants=tor.service
    After=network.target tor.service

[Service] EnvironmentFile=/home/pi/ZeroNet-master/zeronet.conf ExecStart=/home/pi/ZeroNet-master/zeronet.py --tor always User= TimeoutStopSec=30min

[Install] WantedBy=multi-user.target


  3. execute

sudo systemctl daemon-reload sudo systemctl enable zeronet.service sudo reboot


#### Observed Results:

 It displays this 
![grafik](https://user-images.githubusercontent.com/30392780/38772669-b5652842-403c-11e8-897a-9e85d4d6c8c9.png)
error message in the top right corner but it's working fine. It just connects to the zeronet without tor and. The errorlog states:

[2018-04-14 15:57:15,386] WARNING TorManager Tor controller connect error: error: [Errno 111] Connection refused in TorManager.py line 170 > _socket2.py line 228 [2018-04-14 15:57:15,386] INFO TorManager Starting self-bundled Tor, due to Tor proxy port 127.0.0.1:9050 check error: No connection



#### Expected Results:

Zeronet shouldn't establish any connection when Tor isn't reachable and should try to reconnect to Tor if it wasn't available during the initialization.
skwerlman commented 6 years ago

My first guess is that your tor proxy is binding to a unix socket instead of to localhost, which would explain why zeronet can't connect to it.

You also need to make sure tor is configured to accept control connections: https://www.torproject.org/docs/tor-manual.html.en#ControlPort

My last (least likely) guess is that you have some strange firewall rule that's filtering out connections to port 9051.

Lastly, the reason zeronet is being started without a tor connection is that systemd can't know whether tor and zeronet are correctly configured; it can only know that it launched tor and tor didn't error, which is usually good enough.

EDIT: actually it looks like you're misusing EnvironmentFile. Remove that line, and add --config /home/pi/ZeroNet-master/zeronet.conf to the ExecStart line.

FaySmash commented 6 years ago

@skwerlman I probably should have mentioned that this config works totally fine if I start it manually through systemctl start zeronet.service. Tor is correctly configured. The firewall is set to accept everything (turned off). The problem seems to be that zeronet simply starts before tor and because tor hasn't finished initialization yet zeronet just starts without it. The proper way would be to check when tor is ready to connect and if the connection fails for a period of time zeronet should just abort the startup. Running without tor even if it's set to always only because tor wasn't ready during zeronets initialization is a terrible configuration.

I've already tried the --config_path parameter but it's unnecessary anyway, zeronet.py looks for the zeronet.conf in the same folder during the initialization anyway. The EnviromentFile variable is unnecessary.

For more discussion of this topic: https://www.reddit.com/r/zeronet/comments/8bjyht/start_and_end_zeronet_per_initd/

skwerlman commented 6 years ago

Could you try adding Requires=tor.service? According to this After allows a service to start even if the service mentioned isn't started, so it seems like both are needed here.

FaySmash commented 6 years ago

@skwerlman my zeronet.service now looks like this

[Unit]
Description=Zeronet daemon
Requires=tor.service
After=network.target tor.service

[Service]
EnvironmentFile=/home/pi/ZeroNet-master/zeronet.conf
ExecStart=/home/pi/ZeroNet-master/zeronet.py --ui_host 10.0.0.252:43110 misconline.zapto.org
User=pi
TimeoutStopSec=30min

[Install]
WantedBy=multi-user.target

but zeronet still boots up before tor is ready. Also the main part of this opened issue is, that zeronet just connects without tor, even if it's set to always. If I set it to always I want it to only use tor, otherwise stop and disconnect