Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Autostart on Ubuntu 19.04 #10

Closed
sojusnik opened this issue Nov 14, 2019 · 14 comments
Closed

[Enhancement] Autostart on Ubuntu 19.04 #10

sojusnik opened this issue Nov 14, 2019 · 14 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@sojusnik
Copy link

What would be the proper way to configure this program to automatically connect to a VPN at system startup in the background on Ubuntu 19.04?

@Rafficer Rafficer self-assigned this Nov 15, 2019
@Rafficer Rafficer added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 15, 2019
@Rafficer
Copy link
Owner

Rafficer commented Nov 17, 2019

I've written a guide for this now, you can access it currently here: https://github.com/ProtonVPN/protonvpn-cli-ng/blob/master/USAGE.md#via-systemd-service

Would be great if you could give feedback if it worked as expected for you or if anything was unclear!

@sojusnik
Copy link
Author

Thanks for the doc!

My systemd file looks the following, but it won't autoconnect at startup:

[Unit]
Description=ProtonVPN-CLI auto-connect
Wants=network-online.target

[Service]
Type=forking
ExecStart=/usr/local/bin/protonvpn c --cc CH
Environment=SUDO_USER=ubu (that's my PC username, not the openvpn one)

[Install]
WantedBy=multi-user.target

The status shows:

ubu@ntu:~$ systemctl status protonvpn-autoconnect
● protonvpn-autoconnect.service - ProtonVPN-CLI auto-connect
   Loaded: loaded (/etc/systemd/system/protonvpn-autoconnect.service; enabled; vendor preset: enable
   Active: failed (Result: exit-code) since Sun 2019-11-17 20:36:41 CET; 16min ago
  Process: 971 ExecStart=/usr/local/bin/protonvpn c --cc CH (code=exited, status=1/FAILURE)

Nov 17 20:36:41 ntu systemd[1]: Starting ProtonVPN-CLI auto-connect...
Nov 17 20:36:41 ntu protonvpn[971]: [!] There was an error connecting to the ProtonMail API.
Nov 17 20:36:41 ntu protonvpn[971]: [!] Please make sure your connection is working properly!
Nov 17 20:36:41 ntu systemd[1]: protonvpn-autoconnect.service: Control process exited, code=exited, 
Nov 17 20:36:41 ntu systemd[1]: protonvpn-autoconnect.service: Failed with result 'exit-code'.
Nov 17 20:36:41 ntu systemd[1]: Failed to start ProtonVPN-CLI auto-connect.
lines 1-11/11 (END)

I've also found this instruction, that should automatically reconnect, if the connection drops. Does this also apply to your config?

@Rafficer
Copy link
Owner

Seems like your system didn't have access to the internet when it booted.

You could try changing the Wants=network-online.target to Requires=network-online.target

As there is no "waiting for connection" in ProtonVPN-CLI currently, you need to have a working internet connection before this fires up.

@sojusnik
Copy link
Author

Even with Requires=network-online.target I get the same error message as above :/

But if I manually executed sudo systemctl start protonvpn-autoconnect after the system has booted up, then everything works fine.

What about additional settings, like in the instruction linked above, to automatically reconnect on connection drops?

@Rafficer
Copy link
Owner

You can add a Restart=always line, but I fear that this might go ham quite a bit and has some negative effects.

You can also try delaying the unit file, but this may as well have unexpected side effects: https://stackoverflow.com/questions/43001223/how-to-ensure-that-there-is-a-delay-before-a-service-is-started-in-systemd

@sojusnik
Copy link
Author

Adding

[Unit]
Description=ProtonVPN
After=syslog.target network-online.target
Wants=network-online.target

did the trick! Kudos to @Hofer-Julian!

With Restart=always adding

ExecStop=/usr/local/bin/protonvpn d
ExecReload=/usr/local/bin/protonvpn r

is not necessary?

@Rafficer
Copy link
Owner

With Restart=always adding

ExecStop=/usr/local/bin/protonvpn d
ExecReload=/usr/local/bin/protonvpn r

is not necessary?

Depends if you want that. This would just allow you to properly disconnect by using sudo systemctl stop protonvpn-autoconnect and reconnect with sudo systemctl reload protonvpn. If you want that feel free to add it.

The purpose of the guide that I wrote is just to have a "one-shot" auto connect and then manage any further interaction with the CLI.

If this is resolved, please close the issue :)

@sojusnik
Copy link
Author

I take my words back!

[Unit]
After=network-online.target
Wants=network-online.target

or

[Unit]
After=network-online.target
Requires=network-online.target

only work with an already established internet connection at startup. With a cold boot I still get this error message, because I don't have an internet connection when booting.

I've tried

[Unit]
After=NetworkManager-wait-online.service
Requires=NetworkManager-wait-online.service

and

[Unit]
After=systemd-networkd-wait-online.service
Requires=systemd-networkd-wait-online.service

, but only the hackish

[Service]
Restart=on-failure
RestartSec=3

works. But my aim is to connect to the internet only through a VPN, without ever to reveal my true IP. Any ideas how to accomplish that?

@sojusnik sojusnik changed the title Autostart on Ubuntu 19.04 [Enhancement] Autostart on Ubuntu 19.04 Nov 18, 2019
@Rafficer
Copy link
Owner

As said before, you need a working internet connection before being able to start ProtonVPN-CLI. There is currently no "waiting for connection". I think adding this however makes sense, so I will keep this issue open and hopefully get to this in the near future.

@theo-dep
Copy link

Thanks!
On Ubuntu 18.04, I need to add this lines to the tutorial. Otherwise, the protonvpn service ran before the network.

[Unit]
After=network-online.target
Wants=network-online.target

Rafficer added a commit that referenced this issue Nov 23, 2019
This fixes the issues described in #10
@Hofer-Julian
Copy link

Adding

[Unit]
Description=ProtonVPN
After=syslog.target network-online.target
Wants=network-online.target

did the trick! Kudos to @Hofer-Julian!

With Restart=always adding

ExecStop=/usr/local/bin/protonvpn d
ExecReload=/usr/local/bin/protonvpn r

is not necessary?

I just searched for a problem I had with the new protonvpn cli, just to find my name mentioned together the solution.

On Fedora 31 I also had to add

After=network-online.target

for it to work.

@Rafficer
Copy link
Owner

This should generally be fixed when #46 is merged and released :)

Rafficer added a commit that referenced this issue Nov 28, 2019
This fixes the issues described in #10
Rafficer added a commit that referenced this issue Dec 8, 2019
This fixes the issues described in #10
kaplun pushed a commit that referenced this issue Dec 9, 2019
This fixes the issues described in #10
@Rafficer
Copy link
Owner

Rafficer commented Dec 9, 2019

With the merge of #46 this should no longer be an issue. Wait for the next version to be released (hopefully by the end of this week) and then use the PVPN_WAIT feature :)

@dsx12
Copy link

dsx12 commented Apr 28, 2020

For people who are having issues installing protonvpn to start at boot I wrote a simple python script to take care of the work for you:

https://github.com/dsx12/ProtonVpn-Installer/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants