Last active
November 19, 2021 18:52
-
-
Save bodziek666/2ad4aa472219cf4823abe0f67b8b0a89 to your computer and use it in GitHub Desktop.
Manage Flexget daemon which is running inside a separated network namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
NETNS="torrent" | |
FLEXGETDIR="/opt/flexget" | |
# sanity check | |
if [ $# -gt 1 ]; then | |
echo "Too many arguments" | |
exit 1 | |
elif [ $# -lt 1 ]; then | |
echo "Too few arguments, see $0 help for more details" | |
exit 1 | |
fi | |
# check if flexget is running | |
FLEXGETPID=$(pgrep -x flexget) | |
if [ -n "${FLEXGETPID}" ]; then | |
FLEXGETUSER=$(ps -o euser= $FLEXGETPID) | |
else | |
echo "FlexGet daemon is not running, see systemctl status flexget for more details" | |
exit 1 | |
fi | |
# runtime | |
case "${1}" in | |
status) | |
ip netns exec "${NETNS}" sudo -u "${FLEXGETUSER}" "${FLEXGETDIR}/bin/flexget" "daemon" "status" | |
;; | |
reload-config) | |
ip netns exec "${NETNS}" sudo -u "${FLEXGETUSER}" "${FLEXGETDIR}/bin/flexget" "daemon" "reload-config" | |
;; | |
execute) | |
ip netns exec "${NETNS}" sudo -u "${FLEXGETUSER}" "${FLEXGETDIR}/bin/flexget" "execute" | |
;; | |
check) | |
ip netns exec "${NETNS}" sudo -u "${FLEXGETUSER}" "${FLEXGETDIR}/bin/flexget" "check" | |
;; | |
# help: https://flexget.com/Daemon | |
help) | |
echo "Control Flexget Daemon running inside a separated network namespace" | |
echo "Usage:" | |
echo -e "\t$0 status \t\tdisplay status of configured tasks" | |
echo -e "\t$0 reload-config \treload configuration" | |
echo -e "\t$0 execute \t\texecute all tasks immediatelly" | |
echo -e "\t$0 check \t\tcheck configuration" | |
exit 0 | |
;; | |
# exit if invalid/unknown option is used | |
*) | |
echo "Invalid option, see $0 help for more details" | |
exit 1 | |
;; | |
esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/sudoers.d/torrent | |
Cmnd_Alias TR_START=/usr/bin/systemctl start transmission-daemon* | |
Cmnd_Alias TR_STATUS=/usr/bin/systemctl status transmission-daemon* | |
Cmnd_Alias TR_RESTART=/usr/bin/systemctl restart transmission-daemon* | |
Cmnd_Alias TR_STOP=/usr/bin/systemctl stop transmission-daemon* | |
Cmnd_Alias FLEXGETCTL=/usr/local/bin/flexgetctl | |
pawel ALL=(ALL) NOPASSWD: TR_START,TR_STATUS,TR_RESTART,TR_STOP,FLEXGETCTL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sudoers example:
and: