-
-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1174 from BlackOrder/logging-to-stdout-for-HTTP-s…
…erver-and-REST-API Add logging to stdout for HTTP server and REST API
- Loading branch information
Showing
10 changed files
with
316 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,18 @@ MAINTAINER Jookies LTD <[email protected]> | |
RUN groupadd -r jasmin && useradd -r -g jasmin jasmin | ||
|
||
# Install requirements | ||
RUN apt-get update && apt-get install -y \ | ||
libffi-dev \ | ||
libssl-dev \ | ||
# Run python with jemalloc | ||
# - https://zapier.com/engineering/celery-python-jemalloc/ | ||
# - https://paste.pics/581cc286226407ab0be400b94951a7d9 | ||
libjemalloc2 | ||
|
||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* | ||
RUN apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
libffi-dev \ | ||
libssl-dev \ | ||
# Run python with jemalloc | ||
# - https://zapier.com/engineering/celery-python-jemalloc/ | ||
# - https://paste.pics/581cc286226407ab0be400b94951a7d9 | ||
libjemalloc2 \ | ||
; \ | ||
apt-get clean; \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Run python with jemalloc | ||
ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so.2 | ||
|
@@ -26,15 +28,20 @@ ENV RESOURCE_PATH ${CONFIG_PATH}/resource | |
ENV STORE_PATH ${CONFIG_PATH}/store | ||
ENV LOG_PATH /var/log/jasmin | ||
|
||
RUN mkdir -p ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} | ||
RUN mkdir -p ${CONFIG_PATH} ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} | ||
RUN chown jasmin:jasmin ${CONFIG_PATH} ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} | ||
|
||
WORKDIR /build | ||
|
||
RUN pip install --upgrade pip | ||
|
||
COPY . . | ||
|
||
RUN pip install . | ||
|
||
# Clean build dir | ||
RUN rm -rf /build | ||
|
||
# For RestAPI MODE | ||
RUN pip install gunicorn | ||
|
||
|
@@ -45,26 +52,17 @@ COPY misc/config/resource ${RESOURCE_PATH} | |
|
||
WORKDIR /etc/jasmin | ||
|
||
# Default Redis and RabbitMQ connections | ||
# Default Jasmin, Redis, and RabbitMQ connections | ||
ENV JCLI_BIND '0.0.0.0' | ||
ENV AMQP_BROKER_HOST 'rabbitmq' | ||
ENV AMQP_BROKER_PORT 5672 | ||
ENV REDIS_CLIENT_HOST 'redis' | ||
ENV REDIS_CLIENT_PORT 6379 | ||
|
||
# For RestAPI MODE | ||
ENV RESTAPI_MODE 0 | ||
ENV RESTAPI_OLD_HTTP_HOST '127.0.0.1' | ||
|
||
ENV ENABLE_PUBLISH_SUBMIT_SM_RESP 0 | ||
|
||
# Change binding host for jcli | ||
RUN sed -i '/\[jcli\]/a bind=0.0.0.0' ${CONFIG_PATH}/jasmin.cfg | ||
# Change binding port for redis, and amqp | ||
RUN sed -i "/\[redis-client\]/a port=$REDIS_CLIENT_PORT" ${CONFIG_PATH}/jasmin.cfg | ||
RUN sed -i "/\[amqp-broker\]/a port=$AMQP_BROKER_PORT" ${CONFIG_PATH}/jasmin.cfg | ||
# Change binding host for redis, and amqp | ||
RUN sed -i "/\[redis-client\]/a host=$REDIS_CLIENT_HOST" ${CONFIG_PATH}/jasmin.cfg | ||
RUN sed -i "/\[amqp-broker\]/a host=$AMQP_BROKER_HOST" ${CONFIG_PATH}/jasmin.cfg | ||
# For RestAPI http mode | ||
ENV RESTAPI_HTTP_MODE 0 | ||
# For RestAPI Celery worker mode | ||
ENV RESTAPI_WORKER_MODE 0 | ||
|
||
EXPOSE 2775 8990 1401 8080 | ||
VOLUME ["/var/log/jasmin", "/etc/jasmin", "/etc/jasmin/store"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,60 +6,54 @@ MAINTAINER Jookies LTD <[email protected]> | |
RUN addgroup -S jasmin && adduser -S -g jasmin jasmin | ||
|
||
# Install requirements | ||
RUN apk --update add \ | ||
gcc \ | ||
musl-dev \ | ||
libffi-dev \ | ||
openssl-dev \ | ||
python3-dev \ | ||
py3-pip \ | ||
git \ | ||
bash | ||
|
||
# For RestAPI MODE | ||
ENV RESTAPI_MODE 0 | ||
ENV RESTAPI_OLD_HTTP_HOST '127.0.0.1' | ||
|
||
ENV ENABLE_PUBLISH_SUBMIT_SM_RESP 0 | ||
RUN apk --no-cache add \ | ||
libffi-dev \ | ||
openssl-dev \ | ||
bash \ | ||
; \ | ||
rm -vrf /var/cache/apk/* | ||
|
||
ENV ROOT_PATH / | ||
ENV CONFIG_PATH /etc/jasmin | ||
ENV RESOURCE_PATH /etc/jasmin/resource | ||
ENV STORE_PATH /etc/jasmin/store | ||
ENV RESOURCE_PATH ${CONFIG_PATH}/resource | ||
ENV STORE_PATH ${CONFIG_PATH}/store | ||
ENV LOG_PATH /var/log/jasmin | ||
|
||
RUN mkdir -p ${CONFIG_PATH} ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} | ||
RUN chown jasmin:jasmin ${CONFIG_PATH} ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} | ||
|
||
WORKDIR /build | ||
|
||
RUN pip install -e git+https://github.com/jookies/txamqp.git@master#egg=txamqp3 | ||
RUN pip install -e git+https://github.com/jookies/python-messaging.git@master#egg=python-messaging | ||
RUN pip install -e git+https://github.com/jookies/smpp.pdu.git@master#egg=smpp.pdu3 | ||
RUN pip install -e git+https://github.com/jookies/smpp.twisted.git@master#egg=smpp.twisted3 | ||
RUN pip install --upgrade pip | ||
|
||
COPY . . | ||
|
||
RUN pip install . | ||
|
||
# Clean build dir | ||
RUN rm -rf /build | ||
|
||
# For RestAPI MODE | ||
RUN pip install gunicorn | ||
|
||
ENV UNICODEMAP_JP unicode-ascii | ||
|
||
COPY misc/config/*.cfg ${CONFIG_PATH}/ | ||
COPY misc/config/resource/*.xml ${RESOURCE_PATH}/ | ||
COPY misc/config/resource ${RESOURCE_PATH} | ||
|
||
WORKDIR /etc/jasmin | ||
|
||
# Change binding host for jcli | ||
RUN sed -i '/\[jcli\]/a bind=0.0.0.0' ${CONFIG_PATH}/jasmin.cfg | ||
# Change binding port for redis, and amqp | ||
RUN sed -i "/\[redis-client\]/a port=$REDIS_CLIENT_PORT" ${CONFIG_PATH}/jasmin.cfg | ||
RUN sed -i "/\[amqp-broker\]/a port=$AMQP_BROKER_PORT" ${CONFIG_PATH}/jasmin.cfg | ||
# Change binding host for redis, and amqp | ||
RUN sed -i "/\[redis-client\]/a host=$REDIS_CLIENT_HOST" ${CONFIG_PATH}/jasmin.cfg | ||
RUN sed -i "/\[amqp-broker\]/a host=$AMQP_BROKER_HOST" ${CONFIG_PATH}/jasmin.cfg | ||
# Default Jasmin, Redis, and RabbitMQ connections | ||
ENV JCLI_BIND '0.0.0.0' | ||
ENV AMQP_BROKER_HOST 'rabbitmq' | ||
ENV AMQP_BROKER_PORT 5672 | ||
ENV REDIS_CLIENT_HOST 'redis' | ||
ENV REDIS_CLIENT_PORT 6379 | ||
|
||
# For RestAPI http mode | ||
ENV RESTAPI_HTTP_MODE 0 | ||
# For RestAPI Celery worker mode | ||
ENV RESTAPI_WORKER_MODE 0 | ||
|
||
EXPOSE 2775 8990 1401 8080 | ||
VOLUME ["/var/log/jasmin", "/etc/jasmin", "/etc/jasmin/store"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,26 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Change binding host:port for redis, and amqp | ||
sed -i "/\[redis-client\]/,/host=/ s/host=.*/host=$REDIS_CLIENT_HOST/" ${CONFIG_PATH}/jasmin.cfg | ||
sed -i "/\[redis-client\]/,/port=/ s/port=.*/port=$REDIS_CLIENT_PORT/" ${CONFIG_PATH}/jasmin.cfg | ||
sed -i "/\[amqp-broker\]/,/host=/ s/host=.*/host=$AMQP_BROKER_HOST/" ${CONFIG_PATH}/jasmin.cfg | ||
sed -i "/\[amqp-broker\]/,/port=/ s/port=.*/port=$AMQP_BROKER_PORT/" ${CONFIG_PATH}/jasmin.cfg | ||
|
||
# Clean lock files | ||
echo 'Cleaning lock files' | ||
rm -f /tmp/*.lock | ||
|
||
# RestAPI | ||
if [ "$RESTAPI_MODE" = 1 ]; then | ||
# find jasmin installation directory | ||
jasminRoot=$(python -c "import jasmin as _; print(_.__path__[0])") | ||
# update jasmin-restAPI config | ||
sed -i "/# RESTAPI/,/old_api_uri/ s/old_api_uri.*/old_api_uri = 'http:\/\/$RESTAPI_OLD_HTTP_HOST:1401'/" ${jasminRoot}/protocols/rest/config.py | ||
sed -i "/# CELERY/,/broker_url/ s/broker_url.*/broker_url = 'amqp:\/\/guest:guest@$AMQP_BROKER_HOST:$AMQP_BROKER_PORT\/\/'/" ${jasminRoot}/protocols/rest/config.py | ||
sed -i "/# CELERY/,/result_backend/ s/result_backend.*/result_backend = 'redis:\/\/:@$REDIS_CLIENT_HOST:$REDIS_CLIENT_PORT\/1'/" ${jasminRoot}/protocols/rest/config.py | ||
# If RestAPI http Mode, start Guicorn | ||
if [ "$RESTAPI_HTTP_MODE" = 1 ]; then | ||
# start restapi | ||
exec gunicorn -b 0.0.0.0:8080 jasmin.protocols.rest:api --access-logfile /var/log/jasmin/rest-api.access.log --disable-redirect-access-to-syslog | ||
else | ||
if [ "$ENABLE_PUBLISH_SUBMIT_SM_RESP" = 1 ]; then | ||
# Enable publish_submit_sm_resp | ||
echo 'Enabling publish_submit_sm_resp' | ||
sed -i "s/.*publish_submit_sm_resp\s*=.*/publish_submit_sm_resp=True/g" ${CONFIG_PATH}/jasmin.cfg | ||
else | ||
# Disable publish_submit_sm_resp | ||
echo 'Disabling publish_submit_sm_resp' | ||
sed -i "s/.*publish_submit_sm_resp\s*=.*/publish_submit_sm_resp=False/g" ${CONFIG_PATH}/jasmin.cfg | ||
fi | ||
|
||
# If Celery Worker is enabled, start Celery worker | ||
elif [ "$RESTAPI_WORKER_MODE" = 1 ]; then | ||
echo 'Starting Celery worker' | ||
exec celery -A jasmin.protocols.rest.tasks worker -l INFO -c 4 --autoscale=10,3 | ||
|
||
# Else start jasmind | ||
else | ||
if [ "$2" = "--enable-interceptor-client" ]; then | ||
echo 'Starting interceptord' | ||
interceptord.py & | ||
fi | ||
|
||
echo 'Starting jasmind' | ||
exec "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.