You are not logged in.

#1 2016-10-06 13:39:03

ali_molaei
Member
From: Iran
Registered: 2015-12-24
Posts: 63
Website

Tor Service needs to be restarted after system startup

I am using tor and enabled it's service to be started and connected at startup

The problem:
After startup it cannot connect

~$ systemctl status tor
● tor.service - Anonymizing Overlay Network
   Loaded: loaded (/usr/lib/systemd/system/tor.service; enabled; vendor preset: disabled)
   Active: active (running)
 Main PID: 1044 (tor)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/tor.service
           ├─1044 /usr/bin/tor -f /etc/tor/torrc
           └─1045 /usr/bin/python2 /usr/bin/obfsproxy --managed

Oct 06 17:07:30 archlinux Tor[1044]: Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/downloa
Oct 06 17:07:30 archlinux Tor[1044]: Read configuration file "/etc/tor/torrc".
Oct 06 17:07:30 archlinux Tor[1044]: Opening Socks listener on 127.0.0.1:9050
Oct 06 17:07:30 archlinux Tor[1044]: Parsing GEOIP IPv4 file /usr/share/tor/geoip.
Oct 06 17:07:30 archlinux Tor[1044]: Parsing GEOIP IPv6 file /usr/share/tor/geoip6.
Oct 06 17:07:30 archlinux Tor[1044]: Bootstrapped 0%: Starting
Oct 06 17:07:31 archlinux Tor[1044]: Delaying directory fetches: No running bridges
Oct 06 17:07:35 archlinux Tor[1044]: Bootstrapped 5%: Connecting to directory server
Oct 06 17:07:35 archlinux Tor[1044]: Bootstrapped 10%: Finishing handshake with directory server
Oct 06 17:07:35 archlinux Tor[1044]: Proxy Client: unable to connect to [ip:port] ("Network unreachable")

It is saying  ("Network unreachable") but just after startup networkmanager connects to my home wifi!

everytime after startup i have to restart my tor service and then it will connect completly!

very annoying, is there any idea for solving this problem?

Offline

#2 2016-10-06 14:21:35

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: Tor Service needs to be restarted after system startup

One easy workaround would be to disable the tor.service unit, and instead to write/enable a tor.timer timer unit which will launch its associated tor.service some time after startup (for example 1 minute) using its 'OnBootSec=' parameter.

Offline

#3 2016-10-06 16:49:20

loqs
Member
Registered: 2014-03-06
Posts: 17,315

Re: Tor Service needs to be restarted after system startup

Offline

#4 2016-10-08 15:20:17

ali_molaei
Member
From: Iran
Registered: 2015-12-24
Posts: 63
Website

Re: Tor Service needs to be restarted after system startup

berbae wrote:

One easy workaround would be to disable the tor.service unit, and instead to write/enable a tor.timer timer unit which will launch its associated tor.service some time after startup (for example 1 minute) using its 'OnBootSec=' parameter.

I used this trick and it worked, but still it is a problem
if you start your computer and leave it not loged in! then again it cannot connect to network.
the problem is that counting of time starts after boot! isn't there any option to start it from login?

Offline

#5 2016-10-08 15:23:24

ali_molaei
Member
From: Iran
Registered: 2015-12-24
Posts: 63
Website

Re: Tor Service needs to be restarted after system startup

loqs wrote:

Thanks for your reply,

I read this article, it is helpful but i tried to send tor service after NetworkManager and wpa_supplicant and network-online.target and network.target and also NetworkManager-wait-online.service and enabled NetworkManager-wait-online.service

none of them solved the problem hmm

Offline

#6 2016-10-08 18:59:24

loqs
Member
Registered: 2014-03-06
Posts: 17,315

Re: Tor Service needs to be restarted after system startup

Please post the command plus output of the following

$ systemctl cat tor.service
$ systemctl status NetworkManager-wait-online.service

Edit:
Additionally

$ systemctl status tor.service

Last edited by loqs (2016-10-08 19:10:49)

Offline

#7 2016-10-10 19:01:49

ali_molaei
Member
From: Iran
Registered: 2015-12-24
Posts: 63
Website

Re: Tor Service needs to be restarted after system startup

loqs wrote:

Please post the command plus output of the following

$ systemctl cat tor.service
$ systemctl status NetworkManager-wait-online.service

Edit:
Additionally

$ systemctl status tor.service

These are after about 90sec after boot

$ systemctl cat tor.service

# /usr/lib/systemd/system/tor.service
[Unit]
Description=Anonymizing Overlay Network
After=network-online.target

[Service]
User=tor
Type=simple
ExecStart=/usr/bin/tor -f /etc/tor/torrc
ExecReload=/usr/bin/kill -HUP $MAINPID
KillSignal=SIGINT
LimitNOFILE=8192
PrivateDevices=yes

[Install]
WantedBy=multi-user.target

$ systemctl status NetworkManager-wait-online.service

● NetworkManager-wait-online.service - Network Manager Wait Online
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager-wait-online.service; e
   Active: inactive (dead)
     Docs: man:nm-online(1)

status is inactive but it is enabled

$ systemctl status tor.service

● tor.service - Anonymizing Overlay Network
   Loaded: loaded (/usr/lib/systemd/system/tor.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2016-10-10 22:27:01 ; 1min 28s ago
 Main PID: 380 (tor)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/tor.service
           ├─380 /usr/bin/tor -f /etc/tor/torrc
           └─397 /usr/bin/python2 /usr/bin/obfsproxy --managed

Oct 10 22:27:02 archlinux Tor[380]: Opening Socks listener on 127.0.0.1:9050
Oct 10 22:27:02 archlinux Tor[380]: Parsing GEOIP IPv4 file /usr/share/tor/geoip.
Oct 10 22:27:03 archlinux Tor[380]: Parsing GEOIP IPv6 file /usr/share/tor/geoip6.
Oct 10 22:27:03 archlinux Tor[380]: Bootstrapped 0%: Starting
Oct 10 22:27:08 archlinux Tor[380]: new bridge descriptor 'obdurequarterbac' (cached): 
Oct 10 22:27:08 archlinux Tor[380]: Delaying directory fetches: Pluggable transport proxies still configuring
Oct 10 22:27:12 archlinux Tor[380]: Bootstrapped 5%: Connecting to directory server
Oct 10 22:27:12 archlinux Tor[380]: Bootstrapped 10%: Finishing handshake with directory server
Oct 10 22:27:12 archlinux Tor[380]: Proxy Client: unable to connect to ip:port ("Network unreachable")
Oct 10 22:27:13 archlinux Tor[380]: Delaying directory fetches: No running bridges

Offline

#8 2016-10-10 19:31:45

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Tor Service needs to be restarted after system startup

From that systemd article:

[network-online.target] is an active target, meaning that is may be pulled in by the services requiring the network to be up, but is not pulled in by the network management service itself.

You are not pulling it in with that tor.service. You need Requires in addition to After.

Offline

#9 2016-10-10 19:50:18

loqs
Member
Registered: 2014-03-06
Posts: 17,315

Re: Tor Service needs to be restarted after system startup

NetworkTarget

Alternatively, you can change your service that needs the network to be up, to include After=network-online.target and Wants=network-online.target.

So upstream recommends Wants instead of Requires
See man 5 systemd.unit for an explanation of the difference
As a note directly editing the service file instead of overriding it is not recommended as it will be overwritten upon package upgrade.

Offline

#10 2016-10-10 21:13:48

ali_molaei
Member
From: Iran
Registered: 2015-12-24
Posts: 63
Website

Re: Tor Service needs to be restarted after system startup

Raynman wrote:

From that systemd article:

[network-online.target] is an active target, meaning that is may be pulled in by the services requiring the network to be up, but is not pulled in by the network management service itself.

You are not pulling it in with that tor.service. You need Requires in addition to After.

I tried

# /usr/lib/systemd/system/tor.service
[Unit]
Description=Anonymizing Overlay Network
Wants=network-online.target

[Service]
User=tor
Type=simple
ExecStart=/usr/bin/tor -f /etc/tor/torrc
ExecReload=/usr/bin/kill -HUP $MAINPID
KillSignal=SIGINT
LimitNOFILE=8192
PrivateDevices=yes

[Install]
WantedBy=multi-user.target
# /usr/lib/systemd/system/tor.service
[Unit]
Description=Anonymizing Overlay Network
Wants=network-online.target
After=network-online.target

[Service]
User=tor
Type=simple
ExecStart=/usr/bin/tor -f /etc/tor/torrc
ExecReload=/usr/bin/kill -HUP $MAINPID
KillSignal=SIGINT
LimitNOFILE=8192
PrivateDevices=yes

[Install]
WantedBy=multi-user.target
# /usr/lib/systemd/system/tor.service
[Unit]
Description=Anonymizing Overlay Network
Requires=network-online.target
After=network-online.target

[Service]
User=tor
Type=simple
ExecStart=/usr/bin/tor -f /etc/tor/torrc
ExecReload=/usr/bin/kill -HUP $MAINPID
KillSignal=SIGINT
LimitNOFILE=8192
PrivateDevices=yes

[Install]
WantedBy=multi-user.target

only thing changes for all of them was:
$systemctl status NetworkManager-wait-online.service

● NetworkManager-wait-online.service - Network Manager Wait Online
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager-wait-online.service; enabled; vendor preset: disabled)
   Active: active (exited) since Tue 2016-10-11 00:40:22 IRST; 1min 37s ago
     Docs: man:nm-online(1)
  Process: 394 ExecStart=/usr/bin/nm-online -s -q --timeout=30 (code=exited, status=0/SUCCESS)
 Main PID: 394 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 4915)
   CGroup: /system.slice/NetworkManager-wait-online.service

Oct 11 00:40:16 archlinux systemd[1]: Starting Network Manager Wait Online...
Oct 11 00:40:22 archlinux systemd[1]: Started Network Manager Wait Online.

all active (exited)

and status for tor:
the same as past, ("Network unreachable")

Offline

#11 2016-10-11 09:38:15

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: Tor Service needs to be restarted after system startup

ali_molaei wrote:
berbae wrote:

One easy workaround would be to disable the tor.service unit, and instead to write/enable a tor.timer timer unit which will launch its associated tor.service some time after startup (for example 1 minute) using its 'OnBootSec=' parameter.

I used this trick and it worked, but still it is a problem
if you start your computer and leave it not loged in! then again it cannot connect to network.
the problem is that counting of time starts after boot! isn't there any option to start it from login?

Then you could put the timer and the service units in /etc/systemd/user,
and use 'OnStartupSec=' and 'WantedBy=timers.target' for the timer.

Then enable it with:
# systemctl --global enable tor.timer

Edit: change --user with --global as explained in 'man systemctl'

Last edited by berbae (2016-10-11 15:07:57)

Offline

Board footer

Powered by FluxBB