Skip to content

Instantly share code, notes, and snippets.

@alswl
Last active May 27, 2019 09:15
Show Gist options
  • Save alswl/0a2af051b701a6dbfb2bc290be59b37f to your computer and use it in GitHub Desktop.
Save alswl/0a2af051b701a6dbfb2bc290be59b37f to your computer and use it in GitHub Desktop.
bin scripts for Python(uWSGI)
bin scripts for Python(uWSGI)
#!/bin/bash
set -e
set -x
cd "$(dirname "$0")/../"
MD5=md5sum
if [ `uname` = 'Darwin' ]; then
MD5=md5
fi
DEFAULT_PYTHON_EXEC='python3'
REQUIREMENTS_TXT_HASH=`cat requirements.txt | $MD5 | awk '{print $1}'`
DEFAULT_ENV_PATH=".env/$REQUIREMENTS_TXT_HASH"
DEFAULT_VIRTUALENV_EXEC='virtualenv'
if [ -z $ENV_PATH ]; then
ENV_PATH=$DEFAULT_ENV_PATH
fi
if [ -z $PYTHON_EXEC ]; then
PYTHON_EXEC=$DEFAULT_PYTHON_EXEC
fi
if [ -z $VIRTUALENV_EXEC ]; then
VIRTUALENV_EXEC=$DEFAULT_VIRTUALENV_EXEC
fi
if [ ! -d $ENV_PATH ]; then
$VIRTUALENV_EXEC -p `which $PYTHON_EXEC` $ENV_PATH
source $ENV_PATH/bin/activate
pip install -U pip
pip install -r ./requirements.txt
fi
source $ENV_PATH/bin/activate
#!/bin/bash
set -x
cd "$(dirname "$0")/.."
set +e
./bin/stop.sh
set -e
sleep 30
./bin/start.sh
#!/bin/bash
cd "$(dirname "$0")/../"
source bin/init_virtualenv.sh
DEFAULT_UWSGI_PROCESSES=8
DEFAULT_IS_DAEMON="true"
APP_NAME='APP_NAME'
APP_NAME_LOWER='app_name'
DJANGO_APP='app'
PORT=8000
IP="0.0.0.0"
UWSGI_UID=$(id -u admin)
UWSGI_GID=$(id -g admin)
STD_LOG="/tmp/$APP_NAME_LOWER/uwsgi.log"
PID_FILE="/tmp/$APP_NAME_LOWER.pid"
PYTHON_HOME=$(dirname $(dirname $(which python)))
UWSIG_OPTIONS=" --chdir=./
--module=${DJANGO_APP}.wsgi:application
--env DJANGO_SETTINGS_MODULE=${DJANGO_APP}.settings
--http ${IP}:${PORT}
--master
--pidfile ${PID_FILE}
--uid=${UWSGI_UID} --gid=${UWSGI_GID}
--harakiri=20
--max-requests=5000
--vacuum
--home=${PYTHON_HOME}
--enable-threads
"
mkdir -p $(dirname $STD_LOG)
mkdir -p $(dirname $PID_FILE)
APP_NAME_UWSGI_PROCESS="${APP_NAME}_UWSGI_PROCESSES"
if [ -z "${!APP_NAME_UWSGI_PROCESS}" ]; then
UWSGI_PROCESSES=$DEFAULT_UWSGI_PROCESSES
else
UWSGI_PROCESSES=${!APP_NAME_UWSGI_PROCESS}
fi
APP_NAME_IS_DAEMON="${APP_NAME}_IS_DAEMON"
if [ -z "${!APP_NAME_IS_DAEMON}" ]; then
IS_DAEMON=$DEFAULT_IS_DAEMON
else
IS_DAEMON="${!APP_NAME_IS_DAEMON}"
fi
if [ $IS_DAEMON == 'true' ]; then
UWSIG_OPTIONS="$UWSIG_OPTIONS --daemonize ${STD_LOG}"
fi
UWSIG_OPTIONS="$UWSIG_OPTIONS --processes ${UWSGI_PROCESSES}"
uwsgi $UWSIG_OPTIONS
echo '
started.
'
#!/bin/bash
cd "$(dirname "$0")/../"
source bin/init_virtualenv.sh
APP_NAME='APP_NAME'
APP_NAME_LOWER='app_name'
PID_FILE="/var/run/${APP_NAME_LOWER}.pid"
kill -INT `cat ${PID_FILE}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment