Just started using systemd and need to stop and start OpenVPN.

I can successfully start OpenVPN with this for example:

systemctl start openvpn@vpn1.service

and can stop it with:

systemctl stop openvpn@vpn1.service

However I'd like to be able to stop openvpn within a script without having to know which VPN is currently connected. Previously I would use:

service stop openvpn

Is this possible using systemctl?

  • 1
    systemctl stop openvpn.service doesn't work?
    – user49730
    Apr 21, 2015 at 23:36
  • Nope: Failed to stop openvpn.service: Unit openvpn.service not loaded Apr 22, 2015 at 7:41
  • The questioner has no unit named openvpn.service. The question names the units that do exist. Welcome to the concept of template units. Template units are how people use OpenVPN with systemd.
    – JdeBP
    Apr 23, 2015 at 7:29

1 Answer 1


You can use patterns (including shell globs) with systemctl commands. See man systemctl:

shell-style globs will be matched against currently loaded units; literal unit names, with or without a suffix, will be treated as in the first case. This means that literal unit names always refer to exactly one unit, but globs may match zero units and this is not considered an error.

Glob patterns use fnmatch(3), so normal shell-style globbing rules are used, and "*", "?", "[]" may be used. See glob(7) for more details. The patterns are matched against the names of currently loaded units, and patterns which do not match anything are silently skipped. For example:

        # systemctl stop sshd@*.service

will stop all sshd@.service instances.

So, in your case: systemctl stop openvpn* should stop all OpenVPN services.

  • 1
    Indeed this does work, I had tried this before but had dismissed it when an error was shown. What I hadn't actually realised was that the error was from ZSH which was evaluating the * and returning no results. doing this in bash or like this works fine: systemctl stop 'openvpn*' Apr 22, 2015 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.