You are not logged in.

#1 2020-06-01 16:47:32

art
Member
Registered: 2019-08-12
Posts: 49

Auto start OpenVPN after sleep [solved]

How to start OpenVPN after my machine wake up (or reboots) without entering login / pass each time to run it using `sudo`? I've followed steps at https://wiki.archlinux.org/index.php/Op … figuration. But I do `sudo systemctl start MYSERVCIE` each time when I log in / log out.

As far as I see it openvpn deamon does not restart openvpn process when connection is lost. Here are some errors from the unit logs (sudo journalctl -u openvpn-client@***********-direct.service):

...
июн 01 19:40:58 artpc openvpn[5641]: ERROR: Linux route add command failed: external program exited with error status: 2
...
июн 01 19:42:46 artpc openvpn[5641]: ERROR: Linux route delete command failed: external program exited with error status: 2
...
июн 01 19:42:49 artpc openvpn[6526]: Options error: Unrecognized option or missing or extra parameter(s) in [PUSH-OPTIONS]:3: block-outside-dns (2.4.9)
...
июн 01 19:42:49 artpc openvpn[6526]: ERROR: Linux route add command failed: external program exited with error status: 2
...

Have Network Manager set up.

pa -Qs network openvpn
local/networkmanager-openvpn 1.8.12-1
    NetworkManager VPN plugin for OpenVPN
local/openvpn 2.4.9-2
    An easy-to-use, robust and highly configurable VPN (Virtual Private Network)

Last edited by art (2020-06-05 15:50:10)

Offline

#2 2020-06-01 21:51:45

TheStroyer
Member
Registered: 2018-08-28
Posts: 54

Re: Auto start OpenVPN after sleep [solved]

You can enable the systemd unit with the command systemctl enable openvpn@<configutation>.service.
See https://wiki.archlinux.org/index.php/Sy … sing_units for more information.

Offline

#3 2020-06-02 15:18:16

art
Member
Registered: 2019-08-12
Posts: 49

Re: Auto start OpenVPN after sleep [solved]

That does not help. Already done that

Here are logs from OpenVPN when I wake up my notebook from sleep:

> sudo journalctl -u openvpn-client@***.***.***.***-direct.service

...
июн 02 08:18:01 artpc openvpn[6526]: TCP: connect to [AF_INET]***.***.***.***:636 failed: Connection timed out
июн 02 08:18:01 artpc openvpn[6526]: SIGUSR1[connection failed(soft),init_instance] received, process restarting
июн 02 08:18:01 artpc openvpn[6526]: Restart pause, 5 second(s)
июн 02 08:18:06 artpc openvpn[6526]: TCP/UDP: Preserving recently used remote address: [AF_INET]***.***.***.***:636
июн 02 08:18:06 artpc openvpn[6526]: Socket Buffers: R=[131072->131072] S=[16384->16384]
июн 02 08:18:06 artpc openvpn[6526]: Attempting to establish TCP connection with [AF_INET]***.***.***.***:636 [nonblock]
июн 02 08:20:06 artpc openvpn[6526]: TCP: connect to [AF_INET]***.***.***.***:636 failed: Connection timed out
июн 02 08:20:06 artpc openvpn[6526]: SIGUSR1[connection failed(soft),init_instance] received, process restarting
июн 02 08:20:06 artpc openvpn[6526]: Restart pause, 10 second(s)
июн 02 08:20:16 artpc openvpn[6526]: TCP/UDP: Preserving recently used remote address: [AF_INET]***.***.***.***:636
июн 02 08:20:16 artpc openvpn[6526]: Socket Buffers: R=[131072->131072] S=[16384->16384]
июн 02 08:20:16 artpc openvpn[6526]: Attempting to establish TCP connection with [AF_INET]***.***.***.***:636 [nonblock]
... and so on

And after doing only `sudo systemctl restart openvpn-client@***.***.***.***-direct.service` it works. Connection is up.

Last edited by art (2020-06-02 15:26:52)

Offline

#4 2020-06-02 15:27:57

art
Member
Registered: 2019-08-12
Posts: 49

Re: Auto start OpenVPN after sleep [solved]

Offline

#5 2020-06-02 17:10:06

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: Auto start OpenVPN after sleep [solved]

Do not do that.  If you want it moved, please ask using the report link.

Last edited by ewaller (2020-06-02 17:10:20)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#6 2020-06-03 13:51:06

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,787
Website

Re: Auto start OpenVPN after sleep [solved]

Mod note: Moving to Networking.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#7 2020-06-04 13:03:24

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: Auto start OpenVPN after sleep [solved]

Looks like you found a way to restore openvpn connection after waking up system.

How to start OpenVPN after my machine wake up (or reboots) without entering login / pass each time to run it using `sudo`?

Does the system ask for your user password when you execute sudo systemctl restart openvpn-client@***.***.***.***-direct.service and is that what you want to avoid ?

If  not, which login / pass do you want to skip ?


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#8 2020-06-04 13:32:44

art
Member
Registered: 2019-08-12
Posts: 49

Re: Auto start OpenVPN after sleep [solved]

Lone_Wolf wrote:

Does the system ask for your user password when you execute sudo systemctl restart openvpn-client@***.***.***.***-direct.service and is that what you want to avoid ?

Yes, I'd like to automate it so that I don't need to enter login / pass each time I wake up my laptop. Now each time I open console and type `vpnstart` (alias for sudo systemctl restart ..) and then login / pass pair.

Offline

#9 2020-06-04 14:55:40

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: Auto start OpenVPN after sleep [solved]

There are multiple ways to achieve that with sudo .

My personal favorite is Enable explicitly defined commands only for user USER_NAME on host HOST_NAME without password: in https://wiki.archlinux.org/index.php/Su … le_entries .

You would have to convert vpnstart from an alias to a script and remove sudo / su from it as the script is INTENDED to be run with root rights.

Your user would then run it like sudo vpnstart .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#10 2020-06-04 16:01:34

art
Member
Registered: 2019-08-12
Posts: 49

Re: Auto start OpenVPN after sleep [solved]

Thanks for the hit! Did it. A few key presses less smile It works. Though I thought about how to make it without any presses.

Last edited by art (2020-06-04 16:02:10)

Offline

#11 2020-06-04 20:28:28

TheStroyer
Member
Registered: 2018-08-28
Posts: 54

Re: Auto start OpenVPN after sleep [solved]

Offline

#12 2020-06-05 15:49:54

art
Member
Registered: 2019-08-12
Posts: 49

Re: Auto start OpenVPN after sleep [solved]

Thanks! That is solution. Overlooked that :-/

Offline

Board footer

Powered by FluxBB