Correct way of systemd for OpenVPN client on 16.04 Server?
Regarding the "[email protected]" part of your question, another example: I have an OpenVPN configuration file named /etc/openvpn/Germany.conf
so I start the openvpn daemon with systemctl start [email protected]
. This is my default config, so it goes into /etc/default/openvpn
.
In case my german gateway is down, I have another configuration file /etc/openvpn/Netherlands.conf
and to use that I call systemctl start [email protected]
Regarding the Restart setting, this probably goes into the [Service]
section of /etc/systemd/system/multi-user.target.wants/openvpn.service
though I haven't tested that myself.
Note: The above assumes that you use the Ubuntu package via apt-get install openvpn
. I'm not sure what happens when you compile the stuff yourself? Also: Why would you do that?
Related videos on Youtube
gurabli
Updated on September 18, 2022Comments
-
gurabli over 1 year
I'm about to upgrade from 14.04 LTS to 16.04 LTS, but first I need to sort out the systemd services for most important software I use, like OpenVPN client. I have a perfectly working upstart script for 14.04.
I read a lot about systemd, but have no too much experience. From another post I also understand the following:
OpenVPN is a templatized service under systemd. The services are named [email protected]. So you should be starting your /etc/openvpn/myvpn.conf instance with
systemctl start [email protected]
I compile OpenVPN Client. I just don't get this, is [email protected] automatically generated, or how? Further to this, how can I add Restart settings (or any other) to this service, in this case [email protected]? I would like to add
Restart=On-failure
As recommended on freedesktop.org:
Setting this to on-failure is the recommended choice for long-running services, in order to increase reliability by attempting automatic recovery from errors. For services that shall be able to terminate on their own choice (and avoid immediate restarting), on-abnormal is an alternative choice.
My aim is to OpenVPN client to restart always if not stopped by me.
-
gurabli almost 8 yearsThanks for your answer! I was confused with the [email protected] part, now I get it. The restart settings should be Restart=on-failure, and I need to edit the systemd service of the given [email protected] that I want to modify. I used to compile OpenVPN from source, but now I just use the official OpenVPN repository. It is up to date, something that Ubuntu is not most of the time.
-
muru over 7 yearsYou can use
systemctl edit [email protected]
orsystemctl edit [email protected]
, andsystemd
will automatically create that directory for you