morss/morss-helper

48 lines
822 B
Plaintext
Raw Permalink Normal View History

#! /bin/sh
2021-12-29 14:41:03 +00:00
set -ex
if ! command -v python && command -v python3 ; then
alias python='python3'
fi
2021-12-29 14:40:43 +00:00
run() {
2021-12-28 15:30:20 +00:00
gunicorn --bind 0.0.0.0:${PORT:-8000} --preload --access-logfile - morss
}
2021-12-29 14:40:43 +00:00
daemon() {
2021-12-28 15:30:20 +00:00
gunicorn --bind 0.0.0.0:${PORT:-8000} --preload --access-logfile - --daemon morss
}
2021-11-24 20:23:16 +00:00
2021-12-29 14:40:43 +00:00
reload() {
2022-01-19 12:44:15 +00:00
pid=$(pidof 'gunicorn: master [morss]' || true)
# NB. requires python-setproctitle
# `|| true` due to `set -e`
2021-12-28 15:30:20 +00:00
if [ -z "$pid" ]; then
# if gunicorn is not currently running
daemon
2021-11-24 20:23:16 +00:00
2021-12-28 15:30:20 +00:00
else
kill -s USR2 $pid
kill -s WINCH $pid
sleep 1 # give gunicorn some time to reload
kill -s TERM $pid
2021-12-25 17:21:55 +00:00
2021-12-28 15:30:20 +00:00
fi
}
2021-12-29 14:40:43 +00:00
check() {
2021-12-27 15:08:55 +00:00
python -m morss.crawler http://localhost:${PORT:-8000}/ > /dev/null 2>&1
2021-12-28 15:30:20 +00:00
}
2021-12-29 22:35:16 +00:00
if [ -z "$1" ]; then
run
elif [ "$1" = "sh" ] || [ "$1" = "bash" ] || command -v "$1" ; then
2021-12-28 15:30:20 +00:00
$@
2021-12-27 15:08:55 +00:00
else
2021-12-28 15:30:20 +00:00
python -m morss $@
2021-11-24 20:23:16 +00:00
fi