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>
This commit is contained in:
parent
9bf1fa6622
commit
0c06e2a080
|
@ -60,6 +60,14 @@ endef
|
||||||
define Package/nbd/install
|
define Package/nbd/install
|
||||||
$(INSTALL_DIR) $(1)/usr/sbin
|
$(INSTALL_DIR) $(1)/usr/sbin
|
||||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/nbd-client $(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
|
endef
|
||||||
|
|
||||||
$(eval $(call BuildPackage,nbd))
|
$(eval $(call BuildPackage,nbd))
|
||||||
|
|
|
@ -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
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue