Skip to content

Instantly share code, notes, and snippets.

@julcap
Last active December 25, 2020 16:11
Show Gist options
  • Save julcap/93f5bfe78d03809937bdb9cb4f45a220 to your computer and use it in GitHub Desktop.
Save julcap/93f5bfe78d03809937bdb9cb4f45a220 to your computer and use it in GitHub Desktop.
Control qbittorrent-nox running in back ground as service.
#!/usr/bin/env bash
function start {
$exe -d --webui-port=4713 --configuration=/etc/default/qbittorrent-nox --save-path=/etc/default/qbittorrent-nox/torrents
}
function status {
PROCESS=$(ps aux | grep qbittorrent-nox | grep -v 'grep')
PROCESS_ID=$(echo $PROCESS | awk -F" " '{print $2}')
}
function stop {
kill $PROCESS_ID
}
exe=$(which qbittorrent-nox)
if [ -z "$exe" ];then
echo "qbittorrent-nox not found."
exit 1
fi
if [ $1 ]; then
case $1 in
'start')
status
if [ $PROCESS_ID ];then
echo "Already running with process id $PROCESS_ID"
exit 0
fi
start
;;
'stop')
status
if [ -z "$PROCESS" ]; then echo "Not running.";exit 0;fi
echo "Stopping process id $PROCESS_ID"
stop
;;
'status')
status
if [ -z "$PROCESS" ]; then echo "Not running.";exit 0;fi
echo "Running with process id $PROCESS_ID"
;;
*)
echo "Invalid option $1"
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment