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