Method 1. Rc. local mode

Sh #/bin/sh # Check whether the database is enabled # Check whether XX is enabled # Start tomcat Chmod +x start-openvpn.sh 2 Edit/etc/rc. D/rc. Local file, add the script to the file in centos7, / etc/rc. D/rc. Local file permissions are reduced, boot execution in your own scripts is not starting some services, Run the following command to mark the file as an executable file: chmod +x /etc/rc.d/rc.local Open the /etc/rc.d/rc.local file and add the following script to the end: /home/centnet/centnet-service.sh Start VPN. Sh/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpn/openvpnCopy the code

Method 2. Add the automatic startup service

Add the openvpn-client.service file to the /usr/lib/systemd/system directory. [Unit] Description=openvpn-client service After=network.target [Service] Type=forking ExecStart=/etc/openvpn/client/openvpn-client-start.sh start ExecReload=/etc/openvpn/client/openvpn-client-start.sh stop ExecStop=/etc/openvpn/client/openvpn-client-start.sh restart  PrivateTmp=true[Install] WantedBy=multi-user. Target Script#! /bin/sh
# start stop restart
OPER_TYPE=The $1 # Operation type number
"1": stop service "2": start service
declare -A OPER_TYPE_MAP=(
["start"] ="1 2"
["stop"] ="1"
["restart"] ="1 2"
)
# Release logic begins
if [[ ! -n ${OPER_TYPE_MAP[${OPER_TYPE}]}]].then
	echo -e "${GREEN}[ $OPER_TYPE] The operation type does not exist${NC}"
	exit $rc
fi
OPER_TYPE_VALUE=${OPER_TYPE_MAP[${OPER_TYPE}]}
Step 1 check whether the new version file exists
if [[ ${OPER_TYPE_VALUE}= = *"1"*]];then
    echo -e "${GREEN}Stop the service${NC}"
	PROCESS=`ps -ef|grep /usr/sbin/openvpn|grep -v grep|grep -v PPID|awk '{ print $2}'`
	if [ -n "$PROCESS" ]; then 
		echo "kill PID=$PROCESS"
		for i in $PROCESS
		do
			echo "Kill /usr/sbin/openvpn process [ $i]. ""
			kill9 -$i
		done
	fi
fi
Step 2 Start the serviceNohup /usr/sbin/openvpn --config /etc/openvpn/client/ycl-8.13.ovpn > nohup.out 2> &1&then add it to automatic startup systemctlenableOpenvpn-client Systemctl if the openVPn-client service is not automatically starteddisable openvpn-client

Copy the code