Browse Source

nbd: add nbd-client init script

Adds init.d and config files for nbd-client. Each section holds
parameters of one block device, where section name (eg. nbd0) is NBD
device name.

Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
Marcin Jurkowski 9 years ago
parent
commit
0c06e2a080
3 changed files with 86 additions and 0 deletions
  1. 8
    0
      net/nbd/Makefile
  2. 9
    0
      net/nbd/files/nbd-client.conf
  3. 69
    0
      net/nbd/files/nbd-client.init

+ 8
- 0
net/nbd/Makefile View File

@@ -60,6 +60,14 @@ endef
60 60
 define Package/nbd/install
61 61
 	$(INSTALL_DIR) $(1)/usr/sbin
62 62
 	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/nbd-client $(1)/usr/sbin/
63
+	$(INSTALL_DIR) $(1)/etc/config
64
+	$(INSTALL_CONF) ./files/nbd-client.conf $(1)/etc/config/nbd-client
65
+	$(INSTALL_DIR) $(1)/etc/init.d
66
+	$(INSTALL_BIN) ./files/nbd-client.init $(1)/etc/init.d/nbd-client
67
+endef
68
+
69
+define Package/nbd/conffiles
70
+/etc/config/nbd-client
63 71
 endef
64 72
 
65 73
 $(eval $(call BuildPackage,nbd))

+ 9
- 0
net/nbd/files/nbd-client.conf View File

@@ -0,0 +1,9 @@
1
+config nbd-client nbd0
2
+	option enabled '0'
3
+	option server '127.0.0.1'
4
+	option port 10809
5
+	option sdp 0
6
+	option swap 0
7
+	option persist 0
8
+	option blocksize 1024
9
+	option exportname foo

+ 69
- 0
net/nbd/files/nbd-client.init View File

@@ -0,0 +1,69 @@
1
+#!/bin/sh /etc/rc.common
2
+# Copyright (C) 2015 OpenWrt.org
3
+
4
+START=90
5
+STOP=10
6
+USE_PROCD=1
7
+
8
+append_arg() {
9
+	local cfg="$1"
10
+	local var="$2"
11
+	local opt="$3"
12
+	local def="$4"
13
+	local val
14
+
15
+	config_get val "$cfg" "$var"
16
+	[ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
17
+}
18
+
19
+append_bool() {
20
+	local cfg="$1"
21
+	local var="$2"
22
+	local opt="$3"
23
+	local def="$4"
24
+	local val
25
+
26
+	config_get_bool val "$cfg" "$var" "$def"
27
+	[ "$val" = 1 ] && procd_append_param command "$opt"
28
+}
29
+
30
+start_instance() {
31
+	local cfg="$1"
32
+	local enabled
33
+
34
+	config_get_bool enabled "$cfg" 'enabled' '0'
35
+	[ "$enabled" = 0 ] && return 1
36
+
37
+	procd_open_instance
38
+
39
+	procd_set_param command /usr/sbin/nbd-client
40
+
41
+	append_arg "$cfg" server
42
+	append_arg "$cfg" port
43
+	# device path
44
+	procd_append_param command "/dev/$cfg"
45
+	procd_append_param command -nofork
46
+	append_bool "$cfg" sdp "-sdp"
47
+	append_bool "$cfg" swap "-swap"
48
+	append_bool "$cfg" persist "-persist"
49
+	append_arg "$cfg" blocksize "-block-size"
50
+	append_arg "$cfg" timeout "-timeout"
51
+	append_arg "$cfg" exportname "-name"
52
+
53
+	procd_close_instance
54
+}
55
+
56
+service_triggers() {
57
+	procd_add_reload_trigger "nbd-client"
58
+}
59
+
60
+start_service() {
61
+	config_load nbd-client
62
+	config_foreach start_instance nbd-client
63
+}
64
+
65
+stop_service() {
66
+	for dev in /dev/nbd*; do
67
+		nbd-client -d $dev 1>/dev/null 2>&1
68
+	done
69
+}