-
Notifications
You must be signed in to change notification settings - Fork 202
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] Background daemon for connection monitoring #28
Comments
I'm wondering if we can make things like |
Yes, that's the plan. |
I created a stupid simple bash script to automatically reconnect to a random vpn server every time it fails to ping google. It works fine when I run Do you know the reason why the script doesn't work properly on background? |
Yes please! I'd like to have my VPN automatically reconnect when I wake my laptop from sleep. I have already made a systemd service to connect upon boot but it seems to be impossible (for me) to have a systemd system-sleep service to reconnect! |
Might want to take a look at what Mullvad does. I believe they have a background daemon and it works very smoothly. |
Thanks @vinliao for original script.
|
Apology first- I'm no expert programmer! I had an Idea/ question. Is there a process that runs @ waking that you can add |
@TheWindedScriber My first thought would be to enable a service at boot with a dependency on a network connection with Something like: sudo systemctl enable protonvpnd.service But it must require a network connection first in order to work correctly (I think). I'm still a systemd novice 🙂 Something like this could also be more easily packaged downstream into Linux distributions too, if it were committed to this git repo |
I found an example script for a service that runs on wake- not exactly sure how to configure this, but would this template work for example, just to run `[Unit] [Service] [Install] |
Anybody know where we are with this? I'm encountering this issue as well. I mean, it's not the end of the world that I have to run |
It has been a while since I looked, but I can't remember if the process gives an error code if the connection breaks. If it did, it would be easier to write a systemd unit file that monitors the process and restarts automatically if the connection breaks. It could be closed by stopping the service. But in order for that to work, the |
Simple workaround works pretty well for me (alias |
A small modification to the recommanded First let's improve the autostart service to cleanly handle its stop : sudo nano /etc/systemd/system/protonvpn-autoconnect.service Here is the new content (only the [Unit]
Description=ProtonVPN-CLI auto-connect
Wants=network-online.target
[Service]
Type=forking
ExecStart=/usr/local/bin/protonvpn connect -f
ExecStop=/usr/local/protonvpn disconnect
Environment=PVPN_WAIT=300
Environment=PVPN_DEBUG=1
Environment=SUDO_USER=user
[Install]
WantedBy=multi-user.target (of course we have to replace the path to the protonvpn executable in the ExecStop= line with the output of Next you need to create a dedicated service to stop the first one before sleeping and start it when geting out of sleep : sudo nano /etc/systemd/system/protonvpn-suspendresume.service Add the following contents to this file: [Unit]
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=-/usr/bin/systemctl stop protonvpn-autoconnect
ExecStop=-/usr/bin/systemctl start protonvpn-autoconnect
[Install]
WantedBy=sleep.target (this time you need to replace the path to the systemctl executable in the ExecStart= and ExecStop= lines with the output of After that you just need to reload the services: sudo systemctl daemon-reload And enable them: sudo systemctl enable protonvpn-autoconnect protonvpn-suspendresume And now your connection will be cleanly disconnected when suspending and will reconnect when resuming. This is inspired heavily by this stackexchange very good answer. If this seems like an acceptable solution I can provide a PR (just to update the doc with a new paragraph to the Enhancements part. |
I have done exactly what @pymaldebaran suggested in the previous post, however, to accomplish the same goal I needed to do a small change in the protonvpn-autoconnect.service: [Unit]
Description=ProtonVPN-CLI auto-connect
Wants=network-online.target
[Service]
Type=forking
ExecStartPre=/usr/local/bin/protonvpn disconnect
ExecStart=/usr/local/bin/protonvpn connect -f
ExecStop=/usr/local/bin/protonvpn disconnect
Environment=PVPN_WAIT=60
Environment=PVPN_DEBUG=1
Environment=SUDO_USER=user
[Install]
WantedBy=multi-user.target Without the ExecStartPre= line, the service would wait out and throw an exit error. I do think this would be a nice addition to the Enhancements section of the usage guide. |
@dfhssilva With your version do you need the second service that I used to handle the sleeping case ? If not not then it's an impressive improvement over my proposition and indead your suggestion should really be added to the doc. |
@pymaldebaran yes, I still need to do everything as you did, including adding the protonvpn-suspendresume.service. I still think it would be a good addition to the documentation. If needed I can volunteer to do a PR. |
Is your feature request related to a problem? Please describe.
Currently, when a connection goes down the CLI has no way of re-establishing the connection in the event it cuts, as it doesn't run a background service. This also makes it impossible for the CLI to automatically connect on boot or notify the user in such case
Describe the solution you'd like
A background daemon constantly checking the VPN connection and re-establishing it in the event it goes down.
The text was updated successfully, but these errors were encountered: