From 8870400a6ebbda0f355b8f5353aff84b83c82970 Mon Sep 17 00:00:00 2001 From: pictuga Date: Tue, 28 Dec 2021 16:30:20 +0100 Subject: [PATCH] Clean up morss-helper --- morss-helper | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) mode change 100755 => 100644 morss-helper diff --git a/morss-helper b/morss-helper old mode 100755 new mode 100644 index 724b727..da5b5da --- a/morss-helper +++ b/morss-helper @@ -1,21 +1,36 @@ #! /bin/sh - -if [ "$1" = "sh" ] || [ "$1" = "bash" ]; then - exec $@ - -elif [ -z "$1" ] || [ "$@" = "run" ]; then +function run { gunicorn --bind 0.0.0.0:${PORT:-8000} --preload --access-logfile - morss +} -elif [ "$@" = "reload" ]; then - pid=$(pidof 'gunicorn: master [morss]') - kill -s USR2 $pid - kill -s WINCH $pid - kill -s TERM $pid +function daemon { + gunicorn --bind 0.0.0.0:${PORT:-8000} --preload --access-logfile - --daemon morss +} -elif [ "$@" = "check" ]; then +function reload { + pid=$(pidof 'gunicorn: master [morss]') # NB. requires python-setproctitle + + if [ -z "$pid" ]; then + # if gunicorn is not currently running + daemon + + else + kill -s USR2 $pid + kill -s WINCH $pid + sleep 1 # give gunicorn some time to reload + kill -s TERM $pid + + fi +} + +function check { python -m morss.crawler http://localhost:${PORT:-8000}/ > /dev/null 2>&1 +} + +if [ "$1" = "sh" ] || [ "$1" = "bash" ] || [ "$(type -t "$1")" = "function" ]; then + $@ else - morss $@ + python -m morss $@ fi