109 lines
2.1 KiB
Text
109 lines
2.1 KiB
Text
|
#!/bin/sh /etc/rc.common
|
||
|
# Copyright (C) 2012 OpenWrt.org
|
||
|
|
||
|
START=60
|
||
|
SERVICE_USE_PID=1
|
||
|
|
||
|
CONFIGFILE="/var/etc/nbd-server.conf"
|
||
|
|
||
|
|
||
|
append_plain() {
|
||
|
echo "$1" >> $CONFIGFILE
|
||
|
}
|
||
|
|
||
|
append_val_str() {
|
||
|
local resultname="$1"
|
||
|
local cfg="$2"
|
||
|
local uciname="${3:-$1}"
|
||
|
local value=
|
||
|
|
||
|
config_get value "$cfg" "$uciname"
|
||
|
|
||
|
if [ -z "$value" ]; then
|
||
|
return
|
||
|
fi
|
||
|
append_plain "$resultname = $value"
|
||
|
}
|
||
|
|
||
|
append_val_bool() {
|
||
|
local resultname="$1"
|
||
|
local cfg="$2"
|
||
|
local uciname="${3:-$1}"
|
||
|
local value=
|
||
|
|
||
|
config_get_bool value "$cfg" "$uciname"
|
||
|
if [ -z "$value" ]; then
|
||
|
return
|
||
|
fi
|
||
|
|
||
|
[ $value == 1 ] && value="true" || value="false"
|
||
|
append_plain "$resultname = $value"
|
||
|
}
|
||
|
|
||
|
config_handle_generic() {
|
||
|
local cfg="$1"
|
||
|
|
||
|
append_plain "[generic]"
|
||
|
append_val_str user "$cfg"
|
||
|
append_val_str group "$cfg"
|
||
|
append_val_str port "$cfg"
|
||
|
append_val_str listenaddr "$cfg"
|
||
|
append_val_bool allowlist "$cfg"
|
||
|
append_val_str includedir "$cfg"
|
||
|
append_val_bool oldstyle "$cfg"
|
||
|
|
||
|
config_get_bool SERVICE_ENABLED "$cfg" enabled 0
|
||
|
}
|
||
|
|
||
|
config_handle_share() {
|
||
|
local cfg="$1"
|
||
|
|
||
|
append_plain
|
||
|
append_plain "[$cfg]"
|
||
|
append_val_str exportname "$cfg" filename
|
||
|
append_val_str timeout "$cfg"
|
||
|
append_val_str maxconnections "$cfg"
|
||
|
append_val_str authfile "$cfg"
|
||
|
append_val_str filesize "$cfg"
|
||
|
append_val_str readonly "$cfg"
|
||
|
append_val_str multifile "$cfg"
|
||
|
append_val_str copyonwrite "$cfg"
|
||
|
append_val_bool sparse_cow "$cfg"
|
||
|
append_val_bool flush "$cfg"
|
||
|
append_val_bool fua "$cfg"
|
||
|
append_val_bool rotational "$cfg"
|
||
|
append_val_bool sync "$cfg"
|
||
|
append_val_bool discard "$cfg"
|
||
|
append_val_str prerun "$cfg"
|
||
|
append_val_str postrun "$cfg"
|
||
|
append_val_str virtstyle "$cfg"
|
||
|
append_val_str port "$cfg" oldstyle_port
|
||
|
append_val_str listenaddr "$cfg" oldstyle_listenaddr
|
||
|
}
|
||
|
|
||
|
config_read() {
|
||
|
|
||
|
mkdir -p $(dirname $CONFIGFILE)
|
||
|
echo -n > $CONFIGFILE
|
||
|
|
||
|
config_load nbd-server
|
||
|
config_foreach config_handle_generic nbd-server
|
||
|
config_foreach config_handle_share share
|
||
|
}
|
||
|
|
||
|
start() {
|
||
|
config_read
|
||
|
|
||
|
if [ "$SERVICE_ENABLED" = "1" ]; then
|
||
|
service_start /usr/bin/nbd-server \
|
||
|
--pid-file /var/run/nbd-server.pid \
|
||
|
--config-file=$CONFIGFILE
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
stop() {
|
||
|
service_stop /usr/bin/nbd-server
|
||
|
}
|
||
|
|
||
|
|