packages/openvpn: use new service functions, change 'enable' option to 'enabled'...
authorNicolas Thill <nico@openwrt.org>
Wed, 16 Nov 2011 09:44:00 +0000 (09:44 +0000)
committerNicolas Thill <nico@openwrt.org>
Wed, 16 Nov 2011 09:44:00 +0000 (09:44 +0000)
SVN-Revision: 29167

net/openvpn/Makefile
net/openvpn/files/openvpn.config
net/openvpn/files/openvpn.init

index 3e6fa6182a5ff16aeec811236814f6a26fde5749..12715d2f1af4be96c7bd83f22d966d193285c3b5 100644 (file)
@@ -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
index a0539dfd2eff4328e9c8e83cd70c00c413f5f6b1..4a1f66733a55e26a1c7e966e8df2acdf9bddb92a 100644 (file)
@@ -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
index 0fee06d8d4e4f527f86a42d3ae75cc1b0aff5d9d..206763e2b4fba831b156b943da9b8903c3dcb6ce 100644 (file)
@@ -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
 
-       PID="/var/run/openvpn-$s.pid"
+       section_enabled "$s" || return 1
 
-       $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
 }