Skip to content

Commit

Permalink
Deluge Generic Service approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Safihre authored and ymartin59 committed Mar 1, 2018
1 parent d4c3082 commit fbc6a4e
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 394 deletions.
25 changes: 13 additions & 12 deletions spk/deluge/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
SPK_NAME = deluge
SPK_VERS = 1.3.15
SPK_REV = 8
SPK_REV = 9
SPK_ICON = src/deluge.png
DSM_UI_DIR = app
BETA = 1

BUILD_DEPENDS = cross/python cross/setuptools cross/pip cross/wheel
Expand All @@ -13,33 +12,35 @@ SPK_DEPENDS = "python>=2.7.6-8"
REQUIRED_DSM = 5.0
UNSUPPORTED_ARCHS = $(PPC_ARCHES)

MAINTAINER = Diaoul
MAINTAINER = Safihre
DESCRIPTION = Deluge is a full-featured BitTorrent client for Linux, OS X, Unix and Windows. It uses libtorrent in its backend and features multiple user-interfaces including: GTK+, web and console. It has been designed using the client server model with a daemon process that handles all the bittorrent activity. The Deluge daemon is able to run on headless machines with the user-interfaces being able to connect remotely from any platform. This package is intended for advanced users.
ADMIN_PORT = 8112
RELOAD_UI = yes
STARTABLE = yes
CHANGELOG = Update dependencies
DISPLAY_NAME = Deluge

HOMEPAGE = http://deluge-torrent.org
LICENSE = GPL
HELPURL = http://dev.deluge-torrent.org/wiki/UserGuide

INSTALLER_SCRIPT = src/installer.sh
# Custom start-stop script needed due to double-deamon
SSS_SCRIPT = src/dsm-control.sh
FWPORTS = src/${SPK_NAME}.sc
CONF_DIR = src/conf/
WIZARDS_DIR = src/wizard/

INSTALL_PREFIX = /usr/local/$(SPK_NAME)
SERVICE_USER = auto
SERVICE_WIZARD_SHARE = wizard_download_dir
SERVICE_SETUP = src/service-setup.sh
SERVICE_PORT = 8112
SERVICE_PORT_TITLE = $(DISPLAY_NAME)

POST_STRIP_TARGET = deluge_extra_install
# Admin link for in DSM UI
ADMIN_PORT = $(SERVICE_PORT)

POST_STRIP_TARGET = deluge_extra_install

include ../../mk/spksrc.spk.mk

.PHONY: deluge_extra_install
deluge_extra_install:
install -m 755 -d $(STAGING_DIR)/var
install -m 644 src/core.conf $(STAGING_DIR)/var/core.conf
install -m 755 -d $(STAGING_DIR)/app
install -m 644 src/app/config $(STAGING_DIR)/app/config
install -m 644 src/core.conf $(STAGING_DIR)/var/core.conf
15 changes: 0 additions & 15 deletions spk/deluge/src/app/config

This file was deleted.

31 changes: 0 additions & 31 deletions spk/deluge/src/conf/privilege

This file was deleted.

12 changes: 0 additions & 12 deletions spk/deluge/src/deluge.sc

This file was deleted.

78 changes: 41 additions & 37 deletions spk/deluge/src/dsm-control.sh
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
#!/bin/sh

# Package
PACKAGE="deluge"
DNAME="Deluge"
# Default display name
DNAME="${SYNOPKG_PKGNAME}"

# Others
INSTALL_DIR="/usr/local/${PACKAGE}"
PYTHON_DIR="/usr/local/python"
PATH="${INSTALL_DIR}/bin:${INSTALL_DIR}/env/bin:${PYTHON_DIR}/bin:/${PATH}"
PYTHON="${INSTALL_DIR}/env/bin/python"
BUILDNUMBER="$(/bin/get_key_value /etc.defaults/VERSION buildnumber)"
DELUGED="${INSTALL_DIR}/env/bin/deluged"
DELUGE_WEB="${INSTALL_DIR}/env/bin/deluge-web"
CFG_DIR="${INSTALL_DIR}/var/"
DELUGED_PID="${INSTALL_DIR}/var/deluged.pid"
DELUGE_WEB_PID="${INSTALL_DIR}/var/deluge-web.pid"
DELUGED_LOG="${INSTALL_DIR}/var/deluged.log"
DELUGE_WEB_LOG="${INSTALL_DIR}/var/deluge-web.log"
PYTHON_EGG_CACHE="${INSTALL_DIR}/env/cache"
# Source package specific variable and functions
SVC_SETUP=`dirname $0`"/service-setup"
if [ -r "${SVC_SETUP}" ]; then
. "${SVC_SETUP}"
fi

SC_USER="sc-deluge"
LEGACY_USER="deluge"
USER="$([ "${BUILDNUMBER}" -ge "7321" ] && echo -n ${SC_USER} || echo -n ${LEGACY_USER})"
# Required variables to start both processes
# We use Generic Service variables for main deamon
DELUGED="${SYNOPKG_PKGDEST}/env/bin/deluged"
DELUGE_WEB="${SYNOPKG_PKGDEST}/env/bin/deluge-web"
CFG_DIR="${SYNOPKG_PKGDEST}/var/"
PYTHON_EGG_CACHE="${SYNOPKG_PKGDEST}/env/cache"
DELUGE_WEB_PID="${SYNOPKG_PKGDEST}/var/deluge-web.pid"
DELUGE_WEB_LOG="${SYNOPKG_PKGDEST}/var/deluge-web.log"


# We do not need to specify a user,
# since this file is run as the package user anyway
start_daemon ()
{
start-stop-daemon -S -q -x env PYTHON_EGG_CACHE=${PYTHON_EGG_CACHE} ${DELUGED} -c ${USER} -u ${USER} -p ${DELUGED_PID} \
-- --config ${CFG_DIR} --logfile ${DELUGED_LOG} --loglevel info --pidfile ${DELUGED_PID}
start-stop-daemon -S -q -x env PYTHON_EGG_CACHE=${PYTHON_EGG_CACHE} ${DELUGED} -p ${PID_FILE} \
-- --config ${CFG_DIR} --logfile ${LOG_FILE} --loglevel info --pidfile ${PID_FILE}
sleep 3
start-stop-daemon -S -q -b -m -x env PYTHON_EGG_CACHE=${PYTHON_EGG_CACHE} ${DELUGE_WEB} -c ${USER} -u ${USER} -p ${DELUGE_WEB_PID} \
start-stop-daemon -S -q -b -m -x env PYTHON_EGG_CACHE=${PYTHON_EGG_CACHE} ${DELUGE_WEB} -p ${DELUGE_WEB_PID} \
-- --config ${CFG_DIR} --logfile ${DELUGE_WEB_LOG} --loglevel info
}

stop_daemon ()
{
start-stop-daemon -K -q -u ${USER} -p ${DELUGE_WEB_PID}
start-stop-daemon -K -q -u ${USER} -p ${DELUGED_PID}
start-stop-daemon -K -q -p ${DELUGE_WEB_PID}
start-stop-daemon -K -q -p ${PID_FILE}
wait_for_status 1 20
if [ $? -eq 1 ]; then
start-stop-daemon -K -s 9 -q -u ${USER} -p ${DELUGE_WEB_PID}
start-stop-daemon -K -s 9 -q -u ${USER} -p ${DELUGED_PID}
start-stop-daemon -K -s 9 -q -p ${DELUGE_WEB_PID}
start-stop-daemon -K -s 9 -q -p ${PID_FILE}
fi
rm -f ${DELUGED_PID} ${DELUGE_WEB_PID}
rm -f ${PID_FILE} ${DELUGE_WEB_PID}
}

daemon_status ()
{
start-stop-daemon -K -q -t -u ${USER} -p ${DELUGE_WEB_PID}
start-stop-daemon -K -q -t -p ${DELUGE_WEB_PID}
DELUGE_WEB_RETVAL=$?
start-stop-daemon -K -q -t -u ${USER} -p ${DELUGED_PID}
start-stop-daemon -K -q -t -p ${PID_FILE}
DELUGED_RETVAL=$?
[ ${DELUGED_RETVAL} -eq 0 -a ${DELUGE_WEB_RETVAL} -eq 0 ] || return 1
}
Expand All @@ -70,31 +67,38 @@ wait_for_status ()
case $1 in
start)
if daemon_status; then
echo ${DNAME} is already running
echo "${DNAME} is already running"
exit 0
else
echo Starting ${DNAME} ...
echo "Starting ${DNAME} ..."
start_daemon
exit $?
fi
;;
stop)
if daemon_status; then
echo Stopping ${DNAME} ...
echo "Stopping ${DNAME} ..."
stop_daemon
exit $?
else
echo ${DNAME} is not running
echo "${DNAME} is not running"
exit 0
fi
;;
status)
if daemon_status; then
echo ${DNAME} is running
echo "${DNAME} is running"
exit 0
else
echo ${DNAME} is not running
echo "${DNAME} is not running"
exit 1
fi
;;
log)
echo ${DELUGED_LOG}
if [ -n "${LOG_FILE}" -a -r "${LOG_FILE}" ]; then
echo "${LOG_FILE}"
fi
exit 0
;;
*)
exit 1
Expand Down
Loading

0 comments on commit fbc6a4e

Please sign in to comment.