packages/transmission: use new service functions, rename 'run_daemon_as_user' config...
authorNicolas Thill <nico@openwrt.org>
Wed, 16 Nov 2011 09:44:25 +0000 (09:44 +0000)
committerNicolas Thill <nico@openwrt.org>
Wed, 16 Nov 2011 09:44:25 +0000 (09:44 +0000)
SVN-Revision: 29179

net/transmission/Makefile
net/transmission/files/transmission.config
net/transmission/files/transmission.init

index 45f84b930bb0f1fcdc4ade15e810b1c6e90669a0..3dd8df121676a657a1d87ee89e22007088d40f18 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=transmission
 PKG_VERSION:=2.42
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=http://mirrors.m0k.org/transmission/files
index e04473539d37bcc632afea0a0896a71232934e48..ed1ea3303633f0f05848a027084bdc17fca66222 100644 (file)
@@ -1,7 +1,7 @@
 config transmission
        option enabled 0
        option config_dir '/tmp/transmission'
-       option run_daemon_as_user root
+       #option user 'nobody'
        option alt_speed_down 50
        option alt_speed_enabled false
        option alt_speed_time_begin  540
index a3c50212f7cf83ba5393755599c672dc99442098..a7eca423ff8573da9458e27575cbcdede7d2346e 100644 (file)
@@ -1,11 +1,11 @@
 #!/bin/sh /etc/rc.common
+# Copyright (C) 2010-2011 OpenWrt.org
 
 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
@@ -13,7 +13,7 @@ append_params() {
                IFS="$LIST_SEP"
                for v in $v; do
                        [ -n "$v" ] && (
-                               echo "\""$p"\": "$v"," | sed -e 's|_|-|g' >> $config_dir/settings.json
+                               echo "\""$p"\": "$v"," | sed -e 's|_|-|g' >> $config_file
                        )
                done
                unset IFS
@@ -27,29 +27,38 @@ append_params_quotes() {
                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
+                               echo -n "\""$p | sed -e 's|/|\\/|g;s|_|-|g' >> $config_file; \
+                               echo "\": \""$v"\"," >> $config_file
                        )
                done
                unset IFS
        done
 }
 
-start_service() {
+section_enabled() {
+       config_get_bool enabled "$1" 'enabled' 0
+       [ $enabled -gt 0 ]
+}
+
+start_instance() {
        local s="$1"
-       local enabled=0
-       local run_as_usr='root'
+       local user
        local open_file_limit=0
        local ulimit_files=$(ulimit -n)
 
-       # disabled?
-       config_get_bool enabled "$s" enabled 0
-       [ "$enabled" = 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'
+       section_enabled "$section" || return 1
+
+       config_get config_dir "$s" 'config_dir' '/var/etc/transmission'
+       config_get user "$s" 'user'
 
-       echo "{" > $config_dir/settings.json
+       config_file="$config_dir/settings.json"
+       [ -d $config_dir ] || {
+               mkdir -m 0755 -p "$config_dir"
+               touch $config_file
+               [ -z "$user" ] || chown -R $user $config_dir
+       }
+
+       echo "{" > $config_file
 
        append_params "$s" \
                alt_speed_down alt_speed_enabled alt_speed_time_begin alt_speed_time_day \
@@ -74,30 +83,38 @@ start_service() {
                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
+       echo "\""invalid-key"\": false" >> $config_file
+       echo "}" >> $config_file
 
-       config_get open_file_limit "$s" open_file_limit 32
+       config_get open_file_limit "$s" 'open_file_limit' 32
        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"
+       SERVICE_UID="$user" \
+       service_start /usr/bin/transmission-daemon -g $config_dir
 }
 
-start() {
-       config_load transmission
-       config_foreach start_service transmission
+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
 }
 
-stop() {
-       service_kill $(basename $BIN)
+start() {
+       config_load 'transmission'
+       config_foreach start_instance 'transmission'
 }
 
-restart() {
-       stop; sleep 5; start
+stop() {
+       config_load 'transmission'
+       config_foreach stop_instance 'transmission'
 }