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: volumes:
- /opt/mailman/web:/opt/mailman-web-data - /opt/mailman/web:/opt/mailman-web-data
environment: environment:
- UWSGI_WSGI_FILE=wsgi.py - DATABASE_TYPE=postgres
- UWSGI_HTTP=:8000
- UWSGI_WORKERS=2
- UWSGI_THREADS=4
- DATABASE_URL=postgres://mailman:mailmanpass@database/mailmandb - DATABASE_URL=postgres://mailman:mailmanpass@database/mailmandb
- HYPERKITTY_API_KEY=someapikey - HYPERKITTY_API_KEY=someapikey
networks: networks:

View File

@@ -10,20 +10,16 @@ RUN apt-get update \
postgresql-client \ postgresql-client \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN wget -O mailmanclient.zip https://gitlab.com/mailman/mailmanclient/repository/archive.zip?ref=master \ RUN python -m pip install -U mailmanclient==3.1.0 \
&& wget -O postorius.zip https://gitlab.com/mailman/postorius/repository/archive.zip?ref=master \ postorius==1.1.0 \
&& wget -O django-mailman3.zip https://gitlab.com/mailman/django-mailman3/repository/archive.zip?ref=master \ hyperkitty==1.1.0 \
&& wget -O hyperkitty.zip https://gitlab.com/mailman/hyperkitty/repository/archive.zip?ref=master \ django-mailman3==1.1.0 \
&& python -m pip install -U mailmanclient.zip \ whoosh \
postorius.zip \ uwsgi \
hyperkitty.zip \ psycopg2 \
whoosh \ dj-database-url \
uwsgi \ pymysql \
psycopg2 \ && python -m pip install -U django==1.10
dj-database-url \
pymysql \
&& python -m pip install -U django-mailman3.zip \
&& rm mailmanclient.zip postorius.zip hyperkitty.zip django-mailman3.zip
ADD mailman-web /opt/mailman-web ADD mailman-web /opt/mailman-web
@@ -35,4 +31,4 @@ EXPOSE 8000
ENTRYPOINT ["/opt/run.sh"] 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..." echo "DATABASE_URL is not defined. Using sqlite database..."
export DATABASE_URL=sqlite://mailmanweb.db export DATABASE_URL=sqlite://mailmanweb.db
export DATABASE_TYPE='sqlite' export DATABASE_TYPE='sqlite'
else fi
export DATABASE_TYPE='postgres'
if [[ "$DATABASE_TYPE" = 'postgres' ]]; then
wait_for_postgres wait_for_postgres
fi fi
@@ -88,20 +89,10 @@ python manage.py collectstatic --noinput
# this command will upgrade the database. # this command will upgrade the database.
python manage.py migrate 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 $@ 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