From 883cb9ee7c7041068c377834505aeb2d71d1d36c Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 18 Oct 2017 12:44:24 +0200 Subject: [PATCH] Add systemd service file, move Gunicorn config to gunicorn.cfg --- gunicorn.cfg | 5 +++++ oebbapi.service | 20 ++++++++++++++++++++ run.sh | 7 +------ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 gunicorn.cfg create mode 100644 oebbapi.service diff --git a/gunicorn.cfg b/gunicorn.cfg new file mode 100644 index 0000000..5bf197f --- /dev/null +++ b/gunicorn.cfg @@ -0,0 +1,5 @@ +import multiprocessing + +name = "OEBBAPI" +bind = "0.0.0.0:8803" +workers = multiprocessing.cpu_count() * 4 diff --git a/oebbapi.service b/oebbapi.service new file mode 100644 index 0000000..4b751ce --- /dev/null +++ b/oebbapi.service @@ -0,0 +1,20 @@ +[Unit] +Description = OEBBAPI +After = network.target + +[Service] +PermissionsStartOnly = true +PIDFile = /run/oebbapi/oebbapi.pid +User = oebb +Group = oebb +WorkingDirectory = /opt/oebbapi +ExecStartPre = /bin/mkdir /run/oebbapi +ExecStartPre = /bin/chown -R oebb:oebb /run/oebbapi +ExecStart = /usr/bin/env gunicorn -c gunicorn.cfg --pid /run/oebbapi/oebbapi.pid main +ExecReload = /bin/kill -s HUP $MAINPID +ExecStop = /bin/kill -s TERM $MAINPID +ExecStopPost = /bin/rm -rf /run/oebbapi +PrivateTmp = true + +[Install] +WantedBy = multi-user.target diff --git a/run.sh b/run.sh index ab455e7..015379a 100755 --- a/run.sh +++ b/run.sh @@ -1,8 +1,3 @@ #!/bin/bash -ip="0.0.0.0" -port="8803" - -workers=$((`getconf _NPROCESSORS_ONLN` * 4)) - -gunicorn -w $workers -b $ip:$port -n "OEBB API" main +gunicorn -c gunicorn.cfg main