From d8e3724a5e36240041a669cefe2e6586d1f455a4 Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 16 Nov 2011 09:44:00 +0000 Subject: [PATCH] packages/openvpn: use new service functions, change 'enable' option to 'enabled' like most other services are using git-svn-id: svn://svn.openwrt.org/openwrt/packages@29167 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- net/openvpn/Makefile | 2 +- net/openvpn/files/openvpn.config | 6 +-- net/openvpn/files/openvpn.init | 85 ++++++++++++++++---------------- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/net/openvpn/Makefile b/net/openvpn/Makefile index 3e6fa6182..12715d2f1 100644 --- a/net/openvpn/Makefile +++ b/net/openvpn/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=openvpn PKG_VERSION:=2.2.1 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://swupdate.openvpn.net/community/releases @SF/openvpn diff --git a/net/openvpn/files/openvpn.config b/net/openvpn/files/openvpn.config index a0539dfd2..4a1f66733 100644 --- a/net/openvpn/files/openvpn.config +++ b/net/openvpn/files/openvpn.config @@ -7,7 +7,7 @@ package openvpn config openvpn custom_config # Set to 1 to enable this instance: - option enable 0 + option enabled 0 # Include OpenVPN configuration option config /etc/openvpn/my-vpn.conf @@ -21,7 +21,7 @@ config openvpn custom_config config openvpn sample_server # Set to 1 to enable this instance: - option enable 0 + option enabled 0 # Which local IP address should OpenVPN # listen on? (optional) @@ -292,7 +292,7 @@ config openvpn sample_server config openvpn sample_client # Set to 1 to enable this instance: - option enable 0 + option enabled 0 # Specify that we are a client and that we # will be pulling certain config file directives diff --git a/net/openvpn/files/openvpn.init b/net/openvpn/files/openvpn.init index 0fee06d8d..206763e2b 100644 --- a/net/openvpn/files/openvpn.init +++ b/net/openvpn/files/openvpn.init @@ -1,12 +1,14 @@ #!/bin/sh /etc/rc.common -# OpenVPN init script +# Copyright (C) 2008-2011 OpenWrt.org # Copyright (C) 2008 Jo-Philipp Wich # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. START=95 -BIN=/usr/sbin/openvpn -SSD=start-stop-daemon + +SERVICE_DAEMONIZE=1 +SERVICE_WRITE_PID=1 + EXTRA_COMMANDS="up down" LIST_SEP=" @@ -55,15 +57,16 @@ append_params_quoted() { done } -start_service() { +section_enabled() { + config_get_bool enabled "$1" 'enabled' 0 + [ $enabled -gt 0 ] +} + +start_instance() { local s="$1" - local enable=0 - # disabled? - config_get_bool enable "$s" enable 0 - [ "$enable" == 0 ] && return 0 + section_enabled "$s" || return 1 - PID="/var/run/openvpn-$s.pid" ARGS="" # append flags @@ -104,67 +107,63 @@ start_service() { down push up - [ -n "$ARGS" ] && \ - eval "$SSD -q -b -p '$PID' -x $BIN -S -- --syslog 'openvpn($s)' --writepid '$PID' $ARGS" + SERVICE_PID_FILE="/var/run/openvpn-$s.pid" \ + service_start /usr/sbin/openvpn --syslog "openvpn($s)" --writepid "$SERVICE_PID_FILE" $ARGS } -kill_service() { +stop_instance() { local s="$1" - local S="${2:-TERM}" - local enable=0 - # disabled? - config_get_bool enable "$s" enable 0 - [ "$enable" == 1 ] || [ "$S" == "TERM" ] || return 0 + section_enabled "$s" || return 1 - PID="/var/run/openvpn-$s.pid" - - $SSD -q -p $PID -x $BIN -K -s $S - [ "$S" == "TERM" ] && rm -f "$PID" + SERVICE_PID_FILE="/var/run/openvpn-$s.pid" \ + service_stop /usr/sbin/openvpn } -hup_service() { kill_service "$1" HUP; } -stop_service() { kill_service "$1" TERM; } +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_foreach start_service openvpn + config_load 'openvpn' + config_foreach start_instance 'openvpn' } stop() { - config_load openvpn - config_foreach stop_service openvpn + config_load 'openvpn' + config_foreach stop_instance 'openvpn' } reload() { - config_load openvpn - config_foreach hup_service openvpn -} - -restart() { - stop; sleep 5; start + 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 + local instance + config_load 'openvpn' + for instance in "$@"; do + config_get exists "$instance" 'TYPE' if [ "$exists" == "openvpn" ]; then - start_service "$INSTANCE" + start_instance "$instance" fi done } down() { local exists - local INSTANCE - config_load openvpn - for INSTANCE in "$@"; do - config_get exists "$INSTANCE" TYPE + local instance + config_load 'openvpn' + for instance in "$@"; do + config_get exists "$instance" 'TYPE' if [ "$exists" == "openvpn" ]; then - stop_service "$INSTANCE" + stop_instance "$instance" fi done }