Merge pull request #40 from maxking/uwsgi

- Use a config file for uwsgi
- Add qcluster commands to uwsgi as daemons
- Add cron jobs for hyperkitty to uwsgi as crons
- Add a mailman user and run uwsgi as that user
This commit is contained in:
Abhilash Raj
2017-05-28 17:20:26 -07:00
committed by GitHub
4 changed files with 61 additions and 35 deletions

View File

@@ -32,10 +32,7 @@ services:
volumes:
- /opt/mailman/web:/opt/mailman-web-data
environment:
- UWSGI_WSGI_FILE=wsgi.py
- UWSGI_HTTP=:8000
- UWSGI_WORKERS=2
- UWSGI_THREADS=4
- DATABASE_TYPE=postgres
- DATABASE_URL=postgres://mailman:mailmanpass@database/mailmandb
- HYPERKITTY_API_KEY=someapikey
networks:

View File

@@ -10,20 +10,16 @@ RUN apt-get update \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*
RUN wget -O mailmanclient.zip https://gitlab.com/mailman/mailmanclient/repository/archive.zip?ref=master \
&& wget -O postorius.zip https://gitlab.com/mailman/postorius/repository/archive.zip?ref=master \
&& wget -O django-mailman3.zip https://gitlab.com/mailman/django-mailman3/repository/archive.zip?ref=master \
&& wget -O hyperkitty.zip https://gitlab.com/mailman/hyperkitty/repository/archive.zip?ref=master \
&& python -m pip install -U mailmanclient.zip \
postorius.zip \
hyperkitty.zip \
whoosh \
uwsgi \
psycopg2 \
dj-database-url \
pymysql \
&& python -m pip install -U django-mailman3.zip \
&& rm mailmanclient.zip postorius.zip hyperkitty.zip django-mailman3.zip
RUN python -m pip install -U mailmanclient==3.1.0 \
postorius==1.1.0 \
hyperkitty==1.1.0 \
django-mailman3==1.1.0 \
whoosh \
uwsgi \
psycopg2 \
dj-database-url \
pymysql \
&& python -m pip install -U django==1.10
ADD mailman-web /opt/mailman-web
@@ -35,4 +31,4 @@ EXPOSE 8000
ENTRYPOINT ["/opt/run.sh"]
CMD ["uwsgi", "--http-auto-chunked","--http-keepalive"]
CMD ["uwsgi", "--ini", "/opt/mailman-web/uwsgi.ini"]

View File

@@ -49,8 +49,9 @@ if [[ ! -v DATABASE_URL ]]; then
echo "DATABASE_URL is not defined. Using sqlite database..."
export DATABASE_URL=sqlite://mailmanweb.db
export DATABASE_TYPE='sqlite'
else
export DATABASE_TYPE='postgres'
fi
if [[ "$DATABASE_TYPE" = 'postgres' ]]; then
wait_for_postgres
fi
@@ -88,20 +89,10 @@ python manage.py collectstatic --noinput
# this command will upgrade the database.
python manage.py migrate
# Create a mailman user with the specific UID and GID and do not create home
# directory for it. Also chown the logs directory to write the files.
useradd -M -U -u 1000 mailman
chown mailman:mailman /opt/mailman-web-data -R
# Log to the default location /opt/mailman-web-data/logs/uwsgi.log if the
# logging variable is not set.
if [[ ! -v UWSGI_LOGTO ]]; then
echo "No UWSGI_LOGTO defined, logging uwsgi to /opt/mailman-web-data/logs/uwsgi.log ..."
export UWSGI_LOGTO='/opt/mailman-web-data/logs/uwsgi.log'
touch "$UWSGI_LOGTO"
fi
if [[ ! -v UWSGI_WSGI_FILE ]]; then
export UWSGI_WSGI_FILE="wsgi.py"
export UWSGI_HTTP=:8000
export UWSGI_WORKERS=2
export UWSGI_THREADS=4
fi
exec $@

42
web/mailman-web/uwsgi.ini Normal file
View File

@@ -0,0 +1,42 @@
[uwsgi]
# Port on which uwsgi will be listening.
http = :8000
# Move to the directory wher the django files are.
chdir = /opt/mailman-web
# Use the wsgi file provided with the django project.
wsgi-file = wsgi.py
# Setup default number of processes and threads per process.
master = true
process = 2
threads = 2
# Drop privielges and don't run as root.
uid = 1000
gid = 1000
# Setup the django_q related worker processes.
attach-daemon = ./manage.py qcluster
# Setup hyperkitty's cron jobs.
cron2 = unique=1 ./manage.py runjobs minutely
cron2 = hour=1,unique=1 ./manage.py runjobs hourly
cron2 = day=1,unique=1 ./manage.py runjobs monthly
cron2 = week=1,unique=1 ./manage.py runjobs weekly
cron2 = month=1,unique=1 ./manage.py runjobs yearly
# Setup the request log.
req-logger = file:/opt/mailman-web-data/logs/uwsgi.log
# Log cron seperately.
logger = cron file:/opt/mailman-web-data/logs/uwsgi-cron.log
log-route = cron uwsgi-cron
# Log qcluster commands seperately.
logger = qcluster file:/opt/mailman-web-data/logs/uwsgi-qcluster.log
log-route = qcluster uwsgi-daemons
# Last log and it logs the rest of the stuff.
logger = file:/opt/mailman-web-data/logs/uwsgi-error.log