From: Florian Eckert Date: Wed, 20 Dec 2023 09:13:39 +0000 (+0100) Subject: openvpn: add start_path_instance function X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=0b633a08867578fd028c17dd47f3250a22f17da3;p=feed%2Fpackages.git openvpn: add start_path_instance function This commit moves the part for starting an instance to a sub function. Signed-off-by: Florian Eckert --- diff --git a/net/openvpn/files/openvpn.init b/net/openvpn/files/openvpn.init index c282021ae9..791018cc4b 100644 --- a/net/openvpn/files/openvpn.init +++ b/net/openvpn/files/openvpn.init @@ -10,6 +10,7 @@ STOP=10 USE_PROCD=1 PROG=/usr/sbin/openvpn +PATH_INSTANCE_DIR="/etc/openvpn" LIST_SEP=" " @@ -207,28 +208,42 @@ start_uci_instance() { } start_path_instances() { - local path name up down - - for path in /etc/openvpn/*.conf; do - if [ -f "$path" ]; then - name="${path##*/}"; name="${name%.conf}" - - # don't start configs again that are already started by uci - if echo "$UCI_STARTED" | grep -qxF "$path"; then - continue - # don't start configs which are set to disabled in uci - elif echo "$UCI_DISABLED" | grep -qxF "$path"; then - logger -t openvpn "$name.conf is disabled in /etc/config/openvpn" - continue - fi - - get_openvpn_option "$path" up up || up="" - get_openvpn_option "$path" down down || down="" - openvpn_add_instance "$name" "${path%/*}" "$path" "" "$up" "$down" - fi + local path name + + for path in ${PATH_INSTANCE_DIR}/*.conf; do + [ -f "$path" ] && { + name="${path##*/}" + name="${name%.conf}" + start_path_instance "$name" + } done } +start_path_instance() { + local name="$1" + + local path up down + + path="${PATH_INSTANCE_DIR}/${name}.conf" + + # don't start configs again that are already started by uci + if echo "$UCI_STARTED" | grep -qxF "$path"; then + logger -t openvpn "$name.conf already started" + return + fi + + # don't start configs which are set to disabled in uci + if echo "$UCI_DISABLED" | grep -qxF "$path"; then + logger -t openvpn "$name.conf is disabled in /etc/config/openvpn" + return + fi + + get_openvpn_option "$path" up up || up="" + get_openvpn_option "$path" down down || down="" + + openvpn_add_instance "$name" "${path%/*}" "$path" "" "$up" "$down" +} + start_service() { local instance="$1" local instance_found=0