Przeglądaj źródła

nbd: use procd style init script for nbd-server

Runs nbd-server in foreground.

Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
Marcin Jurkowski 9 lat temu
rodzic
commit
5ba490239a
2 zmienionych plików z 23 dodań i 19 usunięć
  1. 1
    1
      net/nbd/Makefile
  2. 22
    18
      net/nbd/files/nbd-server.init

+ 1
- 1
net/nbd/Makefile Wyświetl plik

@@ -53,7 +53,7 @@ endef
53 53
 CONFIGURE_ARGS += \
54 54
 	--disable-glibtest
55 55
 
56
-TARGET_CFLAGS += --std=gnu99
56
+TARGET_CFLAGS += --std=gnu99 -DNODAEMON
57 57
 
58 58
 define Package/nbd/install
59 59
 	$(INSTALL_DIR) $(1)/usr/sbin

+ 22
- 18
net/nbd/files/nbd-server.init Wyświetl plik

@@ -1,9 +1,11 @@
1 1
 #!/bin/sh /etc/rc.common
2
-# Copyright (C) 2012 OpenWrt.org
2
+# Copyright (C) 2015 OpenWrt.org
3 3
 
4 4
 START=60
5
-SERVICE_USE_PID=1
5
+STOP=40
6
+USE_PROCD=1
6 7
 
8
+PROG=/usr/bin/nbd-server
7 9
 CONFIGFILE="/var/etc/nbd-server.conf"
8 10
 
9 11
 
@@ -81,28 +83,30 @@ config_handle_share() {
81 83
 	append_val_str listenaddr "$cfg" oldstyle_listenaddr
82 84
 }
83 85
 
84
-config_read() {
86
+start_instance() {
87
+	local cfg="$1"
88
+	local enabled
85 89
 
86
-	mkdir -p $(dirname $CONFIGFILE)
87
-	echo -n > $CONFIGFILE
90
+	config_get_bool enabled "$cfg" 'enabled' '0'
91
+	[ "$enabled" = 0 ] && return 1
92
+
93
+	procd_open_instance
94
+	procd_set_param command $PROG --config-file=$CONFIGFILE
95
+	procd_set_param file $CONFIGFILE
96
+	procd_close_instance
97
+}
88 98
 
99
+start_service() {
89 100
 	config_load nbd-server
101
+
102
+	mkdir -p $(dirname $CONFIGFILE)
103
+	echo "# auto-generated config file from /etc/config/nbd-server" > $CONFIGFILE
90 104
 	config_foreach config_handle_generic nbd-server
91 105
 	config_foreach config_handle_share share
92
-}
93
-
94
-start() {
95
-	config_read
96 106
 
97
-	if [ "$SERVICE_ENABLED" = "1" ]; then
98
-		service_start /usr/bin/nbd-server \
99
-			--pid-file /var/run/nbd-server.pid \
100
-			--config-file=$CONFIGFILE
101
-	fi
107
+	config_foreach start_instance nbd-server
102 108
 }
103 109
 
104
-stop() {
105
-	service_stop /usr/bin/nbd-server
110
+service_triggers() {
111
+	procd_add_reload_trigger "nbd-server"
106 112
 }
107
-
108
-