77c2fcd235
Currently, transmission daemon allows you to set the max number of open files, but it can be more than allowed by the system, thus resulting in errors if transmission uses more than set in ulimit. The following is a patch to compare ulimit vs open_file_limit from /etc/config/transmission. If the open_file_limit is greater than `ulimit -n`, then invoke ulimit -n open_file_limit + 8 (since transmission's open file limit any seems to pertain only to open torrent files) Signed-off-by: Joe Roback <joe at roback.cc> git-svn-id: svn://svn.openwrt.org/openwrt/packages@25991 3c298f89-4303-0410-b956-a3cf2f4a3e73
102 lines
2.8 KiB
Bash
102 lines
2.8 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
|
|
START=99
|
|
BIN=/usr/bin/transmission-daemon
|
|
SSD=start-stop-daemon
|
|
|
|
LIST_SEP="
|
|
"
|
|
append_params() {
|
|
local p; local v; local s="$1"; shift
|
|
for p in $*; do
|
|
config_get v "$s" "$p"
|
|
IFS="$LIST_SEP"
|
|
for v in $v; do
|
|
[ -n "$v" ] && (
|
|
echo "\""$p"\": "$v"," | sed -e 's|_|-|g' >> $config_dir/settings.json
|
|
)
|
|
done
|
|
unset IFS
|
|
done
|
|
}
|
|
|
|
append_params_quotes() {
|
|
local p; local v; local s="$1"; shift
|
|
for p in $*; do
|
|
config_get v "$s" "$p"
|
|
IFS="$LIST_SEP"
|
|
for v in $v; do
|
|
[ -n "$v" ] && (
|
|
echo -n "\""$p | sed -e 's|/|\\/|g;s|_|-|g' >> $config_dir/settings.json; \
|
|
echo "\": \""$v"\"," >> $config_dir/settings.json
|
|
)
|
|
done
|
|
unset IFS
|
|
done
|
|
}
|
|
|
|
start_service() {
|
|
local s="$1"
|
|
local enable=0
|
|
local enabled=0
|
|
local run_as_usr='root'
|
|
local open_file_limit=0
|
|
local ulimit_files=`ulimit -n`
|
|
|
|
# disabled?
|
|
config_get_bool enable "$s" enable 0 # compatibility with prev version
|
|
config_get_bool enabled "$s" enabled 0
|
|
[ "$enabled" == 0 -a "$enable" == 0 ] && return 0
|
|
config_get config_dir "$s" config_dir '/tmp/transmission'
|
|
mkdir -p "$config_dir"
|
|
config_get run_as_usr "$s" run_daemon_as_user 'root'
|
|
|
|
echo "{" > $config_dir/settings.json
|
|
|
|
append_params "$s" \
|
|
alt_speed_down alt_speed_enabled alt_speed_time_begin alt_speed_time_day \
|
|
alt_speed_time_enabled alt_speed_time_end alt_speed_up blocklist_enabled \
|
|
cache_size_mb dht_enabled encryption idle_seeding_limit idle_seeding_limit_enabled \
|
|
incomplete_dir_enabled lazy_bitfield_enabled lpd_enabled message_level \
|
|
open_file_limit peer_limit_global peer_limit_per_torrent peer_port \
|
|
peer_port_random_high peer_port_random_low peer_port_random_on_start \
|
|
peer_socket_tos pex_enabled port_forwarding_enabled preallocation prefetch_enabled \
|
|
ratio_limit ratio_limit_enabled rename_partial_files rpc_authentication_required \
|
|
rpc_enabled rpc_port rpc_whitelist_enabled script_torrent_done_enabled \
|
|
speed_limit_down speed_limit_down_enabled speed_limit_up \
|
|
speed_limit_up_enabled start_added_torrents trash_original_torrent_files \
|
|
umask upload_slots_per_torrent watch_dir_enabled
|
|
|
|
append_params_quotes "$s" \
|
|
blocklist_url bind_address_ipv4 bind_address_ipv6 download_dir incomplete_dir \
|
|
peer_congestion_algorithm rpc_bind_address rpc_password rpc_url \
|
|
rpc_username rpc_whitelist script_torrent_done_filename watch_dir
|
|
|
|
echo "\""invalid-key"\": false" >> $config_dir/settings.json
|
|
echo "}" >> $config_dir/settings.json
|
|
|
|
chown -R $run_as_usr $config_dir
|
|
|
|
config_get open_file_limit "$s" open_file_limit
|
|
let open_limit_files="$open_file_limit + 8"
|
|
|
|
if [ ${open_file_limit} -gt ${ulimit_files} ]; then
|
|
ulimit -n $open_limit_files
|
|
fi
|
|
|
|
eval "$SSD -c $run_as_usr -q -b -x $BIN -S -- -g $config_dir"
|
|
}
|
|
|
|
start() {
|
|
config_load transmission
|
|
config_foreach start_service transmission
|
|
}
|
|
|
|
stop() {
|
|
service_kill $(basename $BIN)
|
|
}
|
|
|
|
restart() {
|
|
stop; sleep 5; start
|
|
}
|