Skip to content

Instantly share code, notes, and snippets.

@julcap
Created January 2, 2021 13:20
Show Gist options
  • Save julcap/7d60840ecfc26c6e3643aef426752a81 to your computer and use it in GitHub Desktop.
Save julcap/7d60840ecfc26c6e3643aef426752a81 to your computer and use it in GitHub Desktop.
Handle transmission-daemon
#!/usr/bin/env bash
EXECUTABLE_NAME="transmission-daemon"
USER="debian-transmission"
WORKDIR="/var/lib/transmission-daemon/.config/transmission-daemon"
function start {
sudo -u $USER $EXECUTABLE -f --log-error -g $WORKDIR &
}
function status {
PROCESS=$(ps aux | grep $EXECUTABLE_NAME | grep -v 'grep')
PROCESS_ID=$(echo $PROCESS | awk -F" " '{print $2}')
}
function stop {
sudo kill $PROCESS_ID
}
EXECUTABLE=$(which $EXECUTABLE_NAME)
if [ -z "$EXECUTABLE" ];then
echo "$EXECUTABLE_NAME 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
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment