OPNsense Forum

Archive => 20.7 Legacy Series => Topic started by: insecure on September 21, 2020, 04:59:38 pm

Title: Restart OpenVPN via CLI
Post by: insecure on September 21, 2020, 04:59:38 pm
Hello,
i have the need to restart a openvpn service via cli. With pluginctl -s openvpn restart i can restart the first openvpn server. I have multiple openvpn server. Does anybody know how can i restart server2 for example?
Best reguards,
Marc
Title: Re: Restart OpenVPN via CLI
Post by: franco on September 22, 2020, 02:44:05 pm
Hi Marc,

You can use this then: https://github.com/opnsense/core/commit/cf1f4e00b9

# opnsense-patch cf1f4e00b9

Then use the "vpnid" of the OpenVPN instance to restart...

# pluginctl -s openvpn restart 2

Omitting the id will will use the first one it matches. Not a lot of services use this id technique.


Cheers,
Franco
Title: Re: Restart OpenVPN via CLI
Post by: Fright on September 22, 2020, 02:46:05 pm
i cant find it in pluginctl. you can try
Code: [Select]
php -r "require_once '/usr/local/etc/inc/config.inc'; require_once '/usr/local/etc/inc/util.inc'; require_once '/usr/local/etc/inc/interfaces.inc'; require_once '/usr/local/etc/inc/plugins.inc.d/openvpn.inc'; openvpn_configure_single([i]vpninstanseid[/i]);"where vpninstanseid is <vpnid> of server instance in config file
Title: Re: Restart OpenVPN via CLI
Post by: Fright on September 22, 2020, 02:48:11 pm
oops. sorry)
you fix faster than i write
Title: Re: Restart OpenVPN via CLI
Post by: franco on September 22, 2020, 03:14:23 pm
 ;)
Title: Re: Restart OpenVPN via CLI
Post by: Fright on September 22, 2020, 03:38:35 pm
checked. works great. a little clarification on the syntax. instance id should be the last:
# pluginctl -s openvpn restart 2

(because of $filter['id'] = $args[2])
Title: Re: Restart OpenVPN via CLI
Post by: franco on September 22, 2020, 03:39:46 pm
Right, sorry, I forgot "restart" in the post.


Cheers,
Franco
Title: Re: Restart OpenVPN via CLI
Post by: insecure on September 23, 2020, 01:47:31 pm
Thanks alot! Works perfect!
Best reguards, Marc