diff --git a/lib/openvpn_config/linux_client.rb b/lib/openvpn_config/linux_client.rb index 022e54b..aa8b0ad 100644 --- a/lib/openvpn_config/linux_client.rb +++ b/lib/openvpn_config/linux_client.rb @@ -81,7 +81,7 @@ def create_client_credentials(client_hostname, internal_vpn_ip, pptp_vpn_ip, cli def start_openvpn - script = "/sbin/chkconfig openvpn on\n/etc/init.d/openvpn start\n" + script = "/sbin/chkconfig openvpn on\n/etc/init.d/openvpn start || systemctl start openvpn@#{@hostname}.service\n" if Util::Ssh.run_cmd(@external_ip_addr, script, @ssh_as_user, @ssh_identity_file, @logger) then if_down_count=0 1.upto(5) do diff --git a/lib/openvpn_config/server.rb b/lib/openvpn_config/server.rb index 2c94dd5..39af174 100644 --- a/lib/openvpn_config/server.rb +++ b/lib/openvpn_config/server.rb @@ -65,7 +65,7 @@ def configure_vpn_server(hostname) #{IO.read(@ssh_identity_file)} EOF_CAT chmod 600 /root/.ssh/id_rsa - /etc/init.d/openvpn stop + /etc/init.d/openvpn stop || systemctl stop openvpn@server.service clean create_ca '#{hostname}' create_server_key '#{hostname}' @@ -73,7 +73,7 @@ def configure_vpn_server(hostname) init_server_etc_hosts '#{hostname}' '#{@domain_name}' '#{self.vpn_ipaddr}' configure_iptables start_dns_server - /etc/init.d/openvpn start + /etc/init.d/openvpn start || systemctl restart openvpn@server.service /sbin/chkconfig openvpn on if [ -f /etc/redhat-release ]; then diff --git a/lib/openvpn_config/server_functions.bash b/lib/openvpn_config/server_functions.bash index e67569d..ce60cdf 100755 --- a/lib/openvpn_config/server_functions.bash +++ b/lib/openvpn_config/server_functions.bash @@ -122,6 +122,8 @@ function create_client_key { cd $OPENVPN_CONFIG_DIR/easy-rsa bash <<-EOF_BASH . ./vars + export KEY_NAME=$CLIENT_NAME + export KEY_CN=$CLIENT_NAME ./pkitool $CLIENT_NAME &> /dev/null EOF_BASH [[ $? == 0 ]] || fail "Failed to create client key: $CLIENT_NAME." @@ -156,7 +158,7 @@ function create_client_key { echo "$CLIENT_INTERNAL_IP $CLIENT_NAME.$CLIENT_DOMAIN $CLIENT_NAME" >> /etc/hosts fi - /etc/init.d/dnsmasq reload &> /dev/null || /etc/init.d/dnsmasq restart &> /dev/null || { echo "Failed to restart DnsMasq on $HOSTNAME."; return 1; } + /etc/init.d/dnsmasq reload &> /dev/null || /etc/init.d/dnsmasq restart &> /dev/null || systemctl restart dnsmasq.service &> /dev/null || { echo "Failed to restart DnsMasq on $HOSTNAME."; return 1; } } @@ -176,7 +178,7 @@ function start_dns_server { fi /sbin/chkconfig dnsmasq on - /etc/init.d/dnsmasq start + /etc/init.d/dnsmasq start || systemctl restart dnsmasq.service #/sbin/service dnsmasq start }