packages/deluge: use new service functions, add a 'group' config option for holding gid
authorNicolas Thill <nico@openwrt.org>
Wed, 16 Nov 2011 09:44:27 +0000 (09:44 +0000)
committerNicolas Thill <nico@openwrt.org>
Wed, 16 Nov 2011 09:44:27 +0000 (09:44 +0000)
SVN-Revision: 29180

net/deluge/Makefile
net/deluge/files/deluge.config
net/deluge/files/deluge.init

index bf3bba4877d8b87494fcf2055204d93556aa68ac..6e658d303941689de4406ff2dbc6c1fe6b71a1d5 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=deluge
 PKG_VERSION:=1.2.0
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://download.deluge-torrent.org/source/
index 576379f8a6d28a39809285e21057b29b9e8f7ff7..3d4177680bab09880293dfd4ee163d3219ff31ff 100644 (file)
@@ -1,5 +1,6 @@
 config global deluged
-       option 'user' 'deluge:deluge'
+       option 'user' 'deluge'
+       option 'group' 'deluge'
        option 'home' ''
        option 'options' ''
        option 'enabled' 1
index 234a13db68d59f721585517e2320302823b2ab63..50afc2619ebcfac23b7696c2890bc235bbd34a52 100644 (file)
@@ -1,60 +1,86 @@
 #!/bin/sh /etc/rc.common
-# Copyright (C) 2010 OpenWrt.org
+# Copyright (C) 2010-2011 OpenWrt.org
 # Copyright (C) 2010 Alexander Sulfrian
 
-NAME=deluge
-PIDFILE=/var/run/deluged.pid
 START=50
 STOP=50
 
-load_config()
-{
-       config_get_bool enabled $1 enabled 0
-       [ "${enabled}" -eq 0 ] && return 1
+SERVICE_DAEMONIZE=1
+SERVICE_WRITE_PID=1
+SERVICE_PID_FILE="/var/run/deluged.pid"
 
-       config_get user $1 user
-       if [ "${user}" == "" ]; then
-               echo "Please check your uci config. User for '$1' should not be empty."
-               return 1
-       fi
+error() {
+       echo "${initscript}:" "$@" 1>&2
+}
+
+section_enabled() {
+       config_get_bool enabled "$1" 'enabled' 0
+       [ $enabled -gt 0 ]
+}
 
-       username=$(echo ${user} | cut -d ':' -f 1)
-       group=$(echo ${user} | cut -d ':' -f 2)
+start_instance() {
+       local s="$1"
 
-       if ! $(cut -d ':' -f 1 /etc/passwd | grep -sq "${username}"); then
-               echo "Please check your uci config. User for '$1' should exist."
+       section_enabled "$s" || return 1
+
+       config_get uid "$s" 'user'
+       [ -n "$uid" ] || {
+               error "user is not set"
                return 1
-       fi
+       }
+       user_exists $uid || {
+               error "user '$uid' dos not exist"
+               return 1
+       }
+
+       config_get gid "$s" 'group'
+       [ -n "$gid" ] || {
+               error "group is not set"
+               return 1
+       }
+       group_exists $gid || {
+               error "group '$gid' dos not exist"
+               return 1
+       }
 
-       if [ "${group}" != "" ]; then
-               if ! $(cut -d ':' -f 1 /etc/passwd | grep -sq "${group}"); then
-                       echo "Please check your uci config. Group for '$1' should exist."
-                       return 1
-               fi
+       config_get home "$s" 'home'
+       [ -n "$home" ] || {
+               home=$(grep "^${user}:" /etc/passwd | cut -d ':' -f 6)
        fi
+       [ -d "$home" ] || {
+               error "home directory '$home' for user '$uid' dos not exist"
+               return 1
+       }
+
+       config_get options "$s" 'options'
+
+       HOME="$home" \
+       SERVICE_UID="$uid" \
+       SERVICE_GID="$gid" \
+       service_start /usr/bin/python2.6 /usr/bin/deluged --do-not-daemonize $options
 }
 
-start()
-{
-       config_load "${NAME}"
-       load_config deluged || return $?
+stop_instance() {
+       local s="$1"
 
-       config_get options deluged options
+       section_enabled "$s" || return 1
 
-       config_get home deluged home
-       if [ "${home}" == "" ]; then
-               home=$(grep "^${username}:" /etc/passwd | cut -d ':' -f 6)
-       fi
+       config_get uid "$s" 'user'
+       config_get gid "$s" 'group'
 
-       HOME="${home}" /sbin/start-stop-daemon -S -u "${username}" \
-               -p "${PIDFILE}" -b -m -x "/usr/bin/python2.6" -a deluged \
-               -c "${user}" -- --do-not-daemonize ${options}
+       SERVICE_UID="$uid" \
+       SERVICE_GID="$gid" \
+       service_stop /usr/bin/python2.6
 }
 
-stop()
+start()
 {
-       config_load "${NAME}"
-       load_config deluged || return $?
+       config_load 'deluged'
+       config_foreach start_instance 'deluged'
+}
 
-       /sbin/start-stop-daemon -K -u "${username}" -n deluged -p "${PIDFILE}"
+stop()
+{
+       config_load 'deluged'
+       config_foreach stop_instance 'deluged'
 }