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