openvpn: add start_path_instance function
authorFlorian Eckert <fe@dev.tdt.de>
Wed, 20 Dec 2023 09:13:39 +0000 (10:13 +0100)
committerFlorian Eckert <fe@dev.tdt.de>
Wed, 20 Dec 2023 14:01:29 +0000 (15:01 +0100)
This commit moves the part for starting an instance to a sub function.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
net/openvpn/files/openvpn.init

index c282021ae9a60f35426bcfd95c191e64160163e7..791018cc4b669d5bf2e832771516dca4573f9b21 100644 (file)
@@ -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