openvpn: switch to new procd init script style
Signed-off-by: Luka Perkov <luka@openwrt.org> SVN-Revision: 38331
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
				
			|||||||
#
 | 
					#
 | 
				
			||||||
# Copyright (C) 2010-2012 OpenWrt.org
 | 
					# Copyright (C) 2010-2013 OpenWrt.org
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# This is free software, licensed under the GNU General Public License v2.
 | 
					# This is free software, licensed under the GNU General Public License v2.
 | 
				
			||||||
# See /LICENSE for more information.
 | 
					# See /LICENSE for more information.
 | 
				
			||||||
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 | 
				
			|||||||
PKG_NAME:=openvpn
 | 
					PKG_NAME:=openvpn
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PKG_VERSION:=2.3.2
 | 
					PKG_VERSION:=2.3.2
 | 
				
			||||||
PKG_RELEASE=1
 | 
					PKG_RELEASE=2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PKG_SOURCE_URL:=http://swupdate.openvpn.net/community/releases
 | 
					PKG_SOURCE_URL:=http://swupdate.openvpn.net/community/releases
 | 
				
			||||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 | 
					PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,14 @@
 | 
				
			|||||||
#!/bin/sh /etc/rc.common
 | 
					#!/bin/sh /etc/rc.common
 | 
				
			||||||
# Copyright (C) 2008-2011 OpenWrt.org
 | 
					# Copyright (C) 2008-2013 OpenWrt.org
 | 
				
			||||||
# Copyright (C) 2008 Jo-Philipp Wich
 | 
					# Copyright (C) 2008 Jo-Philipp Wich
 | 
				
			||||||
# This is free software, licensed under the GNU General Public License v2.
 | 
					# This is free software, licensed under the GNU General Public License v2.
 | 
				
			||||||
# See /LICENSE for more information.
 | 
					# See /LICENSE for more information.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
START=95
 | 
					START=90
 | 
				
			||||||
 | 
					STOP=10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SERVICE_DAEMONIZE=1
 | 
					USE_PROCD=1
 | 
				
			||||||
SERVICE_WRITE_PID=1
 | 
					PROG=/usr/sbin/openvpn
 | 
				
			||||||
 | 
					 | 
				
			||||||
EXTRA_COMMANDS="up down"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
LIST_SEP="
 | 
					LIST_SEP="
 | 
				
			||||||
"
 | 
					"
 | 
				
			||||||
@@ -21,7 +20,7 @@ append_param() {
 | 
				
			|||||||
		*_*_*)   v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
 | 
							*_*_*)   v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
 | 
				
			||||||
		*_*)     v=${v%%_*}-${v#*_} ;;
 | 
							*_*)     v=${v%%_*}-${v#*_} ;;
 | 
				
			||||||
	esac
 | 
						esac
 | 
				
			||||||
	ARGS="$ARGS --$v"
 | 
						procd_append_param command --"$v"
 | 
				
			||||||
	return 0
 | 
						return 0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,7 +38,7 @@ append_params() {
 | 
				
			|||||||
		config_get v "$s" "$p"
 | 
							config_get v "$s" "$p"
 | 
				
			||||||
		IFS="$LIST_SEP"
 | 
							IFS="$LIST_SEP"
 | 
				
			||||||
		for v in $v; do
 | 
							for v in $v; do
 | 
				
			||||||
			[ -n "$v" ] && append_param "$p" && ARGS="$ARGS $v"
 | 
								[ -n "$v" ] && append_param "$p" && procd_append_param command "$v"
 | 
				
			||||||
		done
 | 
							done
 | 
				
			||||||
		unset IFS
 | 
							unset IFS
 | 
				
			||||||
	done
 | 
						done
 | 
				
			||||||
@@ -58,6 +57,9 @@ start_instance() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	ARGS=""
 | 
						ARGS=""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						procd_open_instance
 | 
				
			||||||
 | 
						procd_set_param command "$PROG" --syslog "openvpn($s)" --writepid "/var/run/openvpn-$s.pid"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# append flags
 | 
						# append flags
 | 
				
			||||||
	append_bools "$s" \
 | 
						append_bools "$s" \
 | 
				
			||||||
		auth_nocache auth_retry auth_user_pass_optional bind ccd_exclusive client client_cert_not_required \
 | 
							auth_nocache auth_retry auth_user_pass_optional bind ccd_exclusive client client_cert_not_required \
 | 
				
			||||||
@@ -92,63 +94,10 @@ start_instance() {
 | 
				
			|||||||
		tun_mtu tun_mtu_extra txqueuelen user verb down push up
 | 
							tun_mtu tun_mtu_extra txqueuelen user verb down push up
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SERVICE_PID_FILE="/var/run/openvpn-$s.pid"
 | 
						procd_close_instance
 | 
				
			||||||
	service_start /usr/sbin/openvpn --syslog "openvpn($s)" --writepid "$SERVICE_PID_FILE" $ARGS
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
stop_instance() {
 | 
					start_service() {
 | 
				
			||||||
	local s="$1"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	section_enabled "$s" || return 1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	SERVICE_PID_FILE="/var/run/openvpn-$s.pid"
 | 
					 | 
				
			||||||
	service_stop /usr/sbin/openvpn
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
reload_instance() {
 | 
					 | 
				
			||||||
	local s="$1"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	section_enabled "$s" || return 1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	SERVICE_PID_FILE="/var/run/openvpn-$s.pid"
 | 
					 | 
				
			||||||
	service_reload /usr/sbin/openvpn
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
start() {
 | 
					 | 
				
			||||||
	config_load 'openvpn'
 | 
						config_load 'openvpn'
 | 
				
			||||||
	config_foreach start_instance 'openvpn'
 | 
						config_foreach start_instance 'openvpn'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
stop() {
 | 
					 | 
				
			||||||
	config_load 'openvpn'
 | 
					 | 
				
			||||||
	config_foreach stop_instance 'openvpn'
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
reload() {
 | 
					 | 
				
			||||||
	config_load 'openvpn'
 | 
					 | 
				
			||||||
	config_foreach reload_instance 'openvpn'
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
up() {
 | 
					 | 
				
			||||||
	local exists
 | 
					 | 
				
			||||||
	local instance
 | 
					 | 
				
			||||||
	config_load 'openvpn'
 | 
					 | 
				
			||||||
	for instance in "$@"; do
 | 
					 | 
				
			||||||
		config_get exists "$instance" 'TYPE'
 | 
					 | 
				
			||||||
		if [ "$exists" == "openvpn" ]; then
 | 
					 | 
				
			||||||
			start_instance "$instance"
 | 
					 | 
				
			||||||
		fi
 | 
					 | 
				
			||||||
	done
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
down() {
 | 
					 | 
				
			||||||
	local exists
 | 
					 | 
				
			||||||
	local instance
 | 
					 | 
				
			||||||
	config_load 'openvpn'
 | 
					 | 
				
			||||||
	for instance in "$@"; do
 | 
					 | 
				
			||||||
		config_get exists "$instance" 'TYPE'
 | 
					 | 
				
			||||||
		if [ "$exists" == "openvpn" ]; then
 | 
					 | 
				
			||||||
			stop_instance "$instance"
 | 
					 | 
				
			||||||
		fi
 | 
					 | 
				
			||||||
	done
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user