#!/bin/sh /etc/rc.common
-# Copyright (C) 2010-2012 OpenWrt.org
+# Copyright (C) 2010-2015 OpenWrt.org
START=99
+USE_PROCD=1
+
LIST_SEP="
"
[ $enabled -gt 0 ]
}
-start_instance() {
- local s="$1"
+transmission() {
+ local cfg="$1"
+ #give transmission 3/5 of the memory of the system
+ local USE
+ local MEM=`grep MemTotal /proc/meminfo|sed 's/ \+/ /g'|cut -d ' ' -f 2`
+ if test "$MEM" -gt 1;then
+ USE=`expr $MEM \* 3000 / 5`
+ fi
+
local user
+ local download_dir
section_enabled "$section" || return 1
- config_get config_dir "$s" 'config_dir' '/var/etc/transmission'
- config_get user "$s" 'user'
+ config_get config_dir "$cfg" 'config_dir' '/var/etc/transmission'
+ config_get user "$cfg" 'user'
+ config_get download_dir "$cfg" 'download_dir' '/var/etc/transmission'
config_file="$config_dir/settings.json"
[ -d $config_dir ] || {
echo "{" > $config_file
- append_params "$s" \
+ append_params "$cfg" \
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 download_queue_enabled download_queue_size \
umask upload_slots_per_torrent utp_enabled scrape_paused_torrents \
watch_dir_enabled
- append_params_quotes "$s" \
+ append_params_quotes "$cfg" \
blocklist_url bind_address_ipv4 bind_address_ipv6 download_dir incomplete_dir \
peer_congestion_algorithm peer_socket_tos rpc_bind_address rpc_password rpc_url \
rpc_username rpc_whitelist script_torrent_done_filename watch_dir
echo "\""invalid-key"\": false" >> $config_file
echo "}" >> $config_file
- SERVICE_UID="$user" \
- service_start /usr/bin/transmission-daemon -g $config_dir
+ procd_open_instance
+ procd_set_param command /usr/bin/transmission-daemon -g $config_dir -f
+ procd_set_param respawn
+ procd_set_param user "$user"
+ if test -z "$USE";then
+ procd_set_param limits core="0 0"
+ else
+ procd_set_param limits core="0 0" as="$USE $USE"
+ logger -t transmission "Starting with $USE virt mem"
+ fi
+
+ procd_add_jail transmission log
+ procd_add_jail_mount $config_file
+ procd_add_jail_mount_rw $download_dir
+ procd_close_instance
}
-stop_instance() {
- local s="$1"
- local user
-
- section_enabled "$section" || return 1
-
- config_get user "$s" 'user'
-
- SERVICE_UID="$user" \
- service_stop /usr/bin/transmission-daemon
-}
-
-start() {
+start_service() {
config_load 'transmission'
- config_foreach start_instance 'transmission'
+ config_foreach transmission 'transmission'
}
-stop() {
- config_load 'transmission'
- config_foreach stop_instance 'transmission'
-}