Skip to content

Instantly share code, notes, and snippets.

@derfalx
Created May 4, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derfalx/476561102e0eb4820be0aaf823956f4e to your computer and use it in GitHub Desktop.
Save derfalx/476561102e0eb4820be0aaf823956f4e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Jump to the correct directory
cd /opt/FaustBot/dev/faust-bot
# Directory of the virtual environment
VENV="./faust-bot-venv"
venv() {
if [ ! -d "$VENV" ]; then
echo "[=== creating virtual environment "
virtualenv --python=/usr/bin/python3 $VENV
echo "[=== activating virtual environment "
source $VENV/bin/activate
echo "[=== installing dependencies "
pip install -r Faust-Bot/requirements.txt
else
echo "[=== activating virtual environment "
source $VENV/bin/activate
fi
}
help() {
echo "Simple script to manage a single faust-bot instance."
echo " -h displays this help message"
echo " -s starts the bot, if it is not running yet"
echo " -e exits/stops the bot"
echo " -r restarts the bot"
echo " -u updates the bots code"
}
start() {
venv
cd Faust-Bot
echo "[=== checking if bot is already running "
if [ -f "../.pid" ]; then
echo "[=== bot is already running "
echo "[=== aborting start "
else
echo "[=== bot is not running "
echo "[=== check if out.txt exists "
if [ -f "../out.txt" ]; then
echo "[=== removing existing out.txt "
rm ../out.txt
else
echo "[=== no out.txt found "
fi
echo "[=== checking if database already exists "
if [ -f "faust_bot.db" ]; then
echo "[=== database already exists "
else
echo "[=== no database "
echo "[=== preparing database "
python ReadInternationalization.py
fi
echo "[=== starting faust-bot "
echo "[=== redirecting output to nohup.out "
nohup python Main.py --config config.txt >../out.txt &
echo "[=== pid of bot process can be found in .pid "
echo $! > ../.pid
fi
cd ..
}
stop() {
echo "[=== checking if bot is running "
if [ ! -f ".pid" ]; then
echo "[=== bot is not running "
else
echo "[=== bot is running "
echo "[=== killing bot process "
kill $(cat .pid)
echo "[=== removing .pid file "
rm .pid
fi
}
update() {
echo "TODO"
}
clean() {
echo "TODO"
}
OPTIND=1
while getopts "hseruc" opt; do
case $opt in
h)
help
exit
;;
s)
start
;;
e)
stop
;;
r)
stop
start
;;
u)
update
;;
c)
clean
;;
\?)
echo "Invalid option: -$OPTARG" >&2
help
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment