From ca84aa7a139c1a33525f4db6a28a99abe45b3405 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Wed, 4 Jan 2017 01:50:41 -0600 Subject: [PATCH] Improve services on boot --- vpnsetup.sh | 18 ++++++++++++------ vpnsetup_centos.sh | 17 +++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/vpnsetup.sh b/vpnsetup.sh index e72daf5..e8692bc 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -387,16 +387,22 @@ exit 0 EOF # Start services at boot -update-rc.d fail2ban enable >/dev/null 2>&1 -systemctl enable fail2ban >/dev/null 2>&1 +for svc in fail2ban ipsec xl2tpd; do + update-rc.d "$svc" enable >/dev/null 2>&1 + systemctl enable "$svc" >/dev/null 2>&1 +done if ! grep -qs "hwdsl2 VPN script" /etc/rc.local; then - conf_bk "/etc/rc.local" - sed --follow-symlinks -i '/^exit 0/d' /etc/rc.local + if [ -f /etc/rc.local ]; then + conf_bk "/etc/rc.local" + sed --follow-symlinks -i '/^exit 0/d' /etc/rc.local + else + echo '#!/bin/sh' > /etc/rc.local + fi cat >> /etc/rc.local <<'EOF' # Added by hwdsl2 VPN script -service ipsec start -service xl2tpd start +service ipsec restart +service xl2tpd restart echo 1 > /proc/sys/net/ipv4/ip_forward exit 0 EOF diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index 1da1918..dd9fd57 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -371,21 +371,26 @@ fi # Start services at boot if grep -qs "release 6" /etc/redhat-release; then - chkconfig iptables on - chkconfig fail2ban on + for svc in iptables fail2ban ipsec xl2tpd; do + chkconfig "$svc" on + done else systemctl --now mask firewalld yum -y install iptables-services || exiterr2 - systemctl enable iptables fail2ban >/dev/null 2>&1 + systemctl enable iptables fail2ban ipsec xl2tpd >/dev/null 2>&1 fi if ! grep -qs "hwdsl2 VPN script" /etc/rc.local; then - conf_bk "/etc/rc.local" + if [ -f /etc/rc.local ]; then + conf_bk "/etc/rc.local" + else + echo '#!/bin/sh' > /etc/rc.local + fi cat >> /etc/rc.local <<'EOF' # Added by hwdsl2 VPN script modprobe -q pppol2tp -service ipsec start -service xl2tpd start +service ipsec restart +service xl2tpd restart echo 1 > /proc/sys/net/ipv4/ip_forward EOF fi