aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Jurkowski <marcin1j@gmail.com>2015-09-02 00:27:36 +0200
committerMarcin Jurkowski <marcin1j@gmail.com>2015-09-02 02:03:38 +0200
commit0c06e2a080727b4bc66f22cfd7c7d249203f69b9 (patch)
tree983cc6567b2b325e6f2ef9f7380ce036b80f1c4b
parent9bf1fa66225fe95eb29c75249fa5821f5159ab93 (diff)
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>
3 files changed, 86 insertions, 0 deletions
diff --git a/net/nbd/Makefile b/net/nbd/Makefile
index dbe61c7c4..aea9e4bfb 100644
--- a/net/nbd/Makefile
+++ b/net/nbd/Makefile
@@ -60,6 +60,14 @@ endef
define Package/nbd/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/nbd-client $(1)/usr/sbin/
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_CONF) ./files/nbd-client.conf $(1)/etc/config/nbd-client
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/nbd-client.init $(1)/etc/init.d/nbd-client
+endef
+
+define Package/nbd/conffiles
+/etc/config/nbd-client
endef
$(eval $(call BuildPackage,nbd))
diff --git a/net/nbd/files/nbd-client.conf b/net/nbd/files/nbd-client.conf
new file mode 100644
index 000000000..e355c6163
--- /dev/null
+++ b/net/nbd/files/nbd-client.conf
@@ -0,0 +1,9 @@
+config nbd-client nbd0
+ option enabled '0'
+ option server '127.0.0.1'
+ option port 10809
+ option sdp 0
+ option swap 0
+ option persist 0
+ option blocksize 1024
+ option exportname foo
diff --git a/net/nbd/files/nbd-client.init b/net/nbd/files/nbd-client.init
new file mode 100644
index 000000000..e10c22044
--- /dev/null
+++ b/net/nbd/files/nbd-client.init
@@ -0,0 +1,69 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2015 OpenWrt.org
+
+START=90
+STOP=10
+USE_PROCD=1
+
+append_arg() {
+ local cfg="$1"
+ local var="$2"
+ local opt="$3"
+ local def="$4"
+ local val
+
+ config_get val "$cfg" "$var"
+ [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
+}
+
+append_bool() {
+ local cfg="$1"
+ local var="$2"
+ local opt="$3"
+ local def="$4"
+ local val
+
+ config_get_bool val "$cfg" "$var" "$def"
+ [ "$val" = 1 ] && procd_append_param command "$opt"
+}
+
+start_instance() {
+ local cfg="$1"
+ local enabled
+
+ config_get_bool enabled "$cfg" 'enabled' '0'
+ [ "$enabled" = 0 ] && return 1
+
+ procd_open_instance
+
+ procd_set_param command /usr/sbin/nbd-client
+
+ append_arg "$cfg" server
+ append_arg "$cfg" port
+ # device path
+ procd_append_param command "/dev/$cfg"
+ procd_append_param command -nofork
+ append_bool "$cfg" sdp "-sdp"
+ append_bool "$cfg" swap "-swap"
+ append_bool "$cfg" persist "-persist"
+ append_arg "$cfg" blocksize "-block-size"
+ append_arg "$cfg" timeout "-timeout"
+ append_arg "$cfg" exportname "-name"
+
+ procd_close_instance
+}
+
+service_triggers() {
+ procd_add_reload_trigger "nbd-client"
+}
+
+start_service() {
+ config_load nbd-client
+ config_foreach start_instance nbd-client
+}
+
+stop_service() {
+ for dev in /dev/nbd*; do
+ nbd-client -d $dev 1>/dev/null 2>&1
+ done
+}