summaryrefslogtreecommitdiff
path: root/network/qbittorrent/rc.qbittorrent-nox.new
diff options
context:
space:
mode:
authorDavid Woodfall <dave@dawoodfall.net>2015-11-25 18:12:26 +0700
committerWilly Sudiarto Raharjo <willysr@slackbuilds.org>2015-11-28 07:25:59 +0700
commit930330f99242481c2b07ed7d549caca9efe47dee (patch)
tree330417f2223838527ceab4031f6db068a6b7f66e /network/qbittorrent/rc.qbittorrent-nox.new
parentc70dba9b054066bab035025403a1ba97c9d2439f (diff)
downloadslackbuilds-930330f99242481c2b07ed7d549caca9efe47dee.tar.gz
network/qbittorrent: Added qbittorrent-nox + an rc init script.
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'network/qbittorrent/rc.qbittorrent-nox.new')
-rw-r--r--network/qbittorrent/rc.qbittorrent-nox.new82
1 files changed, 82 insertions, 0 deletions
diff --git a/network/qbittorrent/rc.qbittorrent-nox.new b/network/qbittorrent/rc.qbittorrent-nox.new
new file mode 100644
index 0000000000..f2c3c6218b
--- /dev/null
+++ b/network/qbittorrent/rc.qbittorrent-nox.new
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+# /etc/rc.d/rc.qbittorrent-nox
+# Runs qbittorrent webui under user who started the script.
+# Usage: /etc/rc.d/rc.qbittorrent-nox start <PORT>|stop|restart <PORT>|status
+# Port defaults to 8080 if not provided.
+#
+# To run this script from rc.local you must run it as a non-root user.
+#
+# Example:
+# /bin/su - david -c /etc/rc.d/rc.qbittorrent-nox start 9000
+# Program output is sent to /tmp/qbittorrent-nox-$USER
+
+# First some checks to see what's what.
+
+if [ "$USER" = "root" ] && [ "$1" = "start" ]; then
+ echo "Do not start the daemon as root." >/dev/stderr
+ exit 1
+fi
+
+
+if [ -n "$2" ]; then
+ UIPORT="$2"
+else
+ UIPORT="8080"
+fi
+
+LOG="/tmp/qbittorrent-nox-$USER"
+APP="/usr/bin/qbittorrent-nox"
+
+do_start()
+{
+ if [ -n "$(/bin/netstat -nta | awk '{print $4}' \
+ | cut -d: -f2 | grep $UIPORT | grep 0.0.0.0)" ]; then
+
+ echo "Port $UIPORT is already in use." >/dev/stderr
+ exit 1
+ fi
+
+ $APP --webui-port=$UIPORT 1>$LOG 2>&1 &
+}
+
+do_stop()
+{
+ PID="$(pgrep -u $USER qbittorrent-nox)"
+
+ if [ -n "$PID" ]; then
+ echo "Killing PID $PID"
+ kill $PID
+ else
+ echo "No process found." >/dev/stderr
+ fi
+}
+
+do_status()
+{
+ echo "Local Address Foreign Address State PID/Program name"
+ /bin/netstat -pntl 2>&1 | grep qbittorrent-n \
+ | awk '{print $4 " " $5 " " $6 " " $7}'
+}
+
+case "$1" in
+ 'start')
+ do_start
+ ;;
+
+ 'stop')
+ do_stop
+ ;;
+ 'restart')
+ do_stop
+ sleep 1
+ do_start
+ ;;
+ 'status')
+ do_status
+ ;;
+ *)
+ echo "Usage: $0 {start <PORT>|stop|restart <PORT>|status}" >/dev/stderr
+ exit 1
+ ;;
+esac