From 29204b6fb5c28477bef9361b39ce0df74db1ec44 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 7 Mar 2016 14:25:24 +0530 Subject: [PATCH] move gunicorn configuration from init script to config file --- ctl | 4 ++++ etc/init/pandora.conf | 10 ++-------- etc/systemd/pandora.service | 9 +-------- pandora/gunicorn_config.py.in | 5 +++++ update.py | 17 +++++++++++++++++ 5 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 pandora/gunicorn_config.py.in diff --git a/ctl b/ctl index 8a1a4db07..bb8d8d7b8 100755 --- a/ctl +++ b/ctl @@ -27,6 +27,9 @@ if [ "$action" = "init" ]; then done cd ${BASE} ./bin/pip install -r requirements.txt + if [ ! -e pandora/gunicorn_config.py ]; then + cp pandora/gunicorn_config.py.in pandora/gunicorn_config.py + fi exit 0 fi if [ `whoami` != 'root' ]; then @@ -41,6 +44,7 @@ if [ "$action" = "install" ]; then cp $BASE/etc/systemd/*.service /lib/systemd/system/ cp $BASE/etc/tmpfiles.d/pandora.conf /usr/lib/tmpfiles.d/ systemd-tmpfiles --create /usr/lib/tmpfiles.d/pandora.conf >/dev/null || true + systemctl daemon-reload for service in $SERVICES; do systemctl enable ${service}.service done diff --git a/etc/init/pandora.conf b/etc/init/pandora.conf index 0abbc4e71..673f19d04 100644 --- a/etc/init/pandora.conf +++ b/etc/init/pandora.conf @@ -22,11 +22,5 @@ end script exec start-stop-daemon \ --start -c $USER -d $VENV/pandora --exec \ - $VENV/bin/gunicorn -- \ - wsgi:application \ - --bind 127.0.0.1:2620 \ - --timeout 90 \ - --max-requests 1000 \ - -p /var/run/pandora/pandora.pid \ - --log-level info --log-file /var/log/pandora/pandora.log \ - --workers 5 + $VENV/bin/gunicorn -- wsgi:application \ + -c $VENV/pandora/gunicorn_config.py -p /var/run/pandora/pandora.pid diff --git a/etc/systemd/pandora.service b/etc/systemd/pandora.service index f32f940ee..6b7f77e0e 100644 --- a/etc/systemd/pandora.service +++ b/etc/systemd/pandora.service @@ -11,14 +11,7 @@ WorkingDirectory=/srv/pandora/pandora StandardOutput=syslog StandardError=syslog ExecStartPre=/srv/pandora/pandora/manage.py compile_pyc -p /srv/pandora/pandora -ExecStart=/srv/pandora/bin/gunicorn \ - wsgi:application \ - -p /run/pandora/pandora.pid \ - --bind 127.0.0.1:2620 \ - --timeout 90 \ - --max-requests 1000 \ - --log-level info \ - --workers 5 +ExecStart=/srv/pandora/bin/gunicorn wsgi:application -c gunicorn_config.py -p $MAINPID ExecReload=/bin/kill -HUP $MAINPID [Install] diff --git a/pandora/gunicorn_config.py.in b/pandora/gunicorn_config.py.in new file mode 100644 index 000000000..4e8137fa1 --- /dev/null +++ b/pandora/gunicorn_config.py.in @@ -0,0 +1,5 @@ +bind="127.0.0.1:2620" +log_level="info" +max_requests=1000 +timeout=90 +workers=5 diff --git a/update.py b/update.py index ae31bdcf8..f5b17b5d4 100755 --- a/update.py +++ b/update.py @@ -197,6 +197,23 @@ if __name__ == "__main__": path = os.path.join(pandora.settings.GEOIP_PATH, 'GeoLite2-City.mmdb') if not os.path.exists(path): run('./pandora/manage.py', 'update_geoip') + if old <= 5443: + gunicorn_config = 'pandora/gunicorn_config.py' + if not os.path.exists(gunicorn_config): + shutil.copy('%s.in'%gunicorn_config, gunicorn_config) + if os.path.exists('/etc/init/pandora.conf'): + with open('/etc/init/pandora.conf') as fd: + data = fd.read() + if '0.0.0.0:2620' in data: + run('sed', '-i', 's/127.0.0.1:2620/0.0.0.0:2620/g', gunicorn_config) + if old > 5389: + service = 'pandora' + print('Please install new init script for "%s" service:' % service) + if os.path.exists('/etc/init'): + print('\tsudo cp %s/etc/init/%s.conf /etc/init/' % (base, service)) + if os.path.exists('/lib/systemd/system'): + print('\tsudo cp %s/etc/systemd/%s.service /lib/systemd/system/' % (base, service)) + print('\tsudo service %s restart' % service) else: if len(sys.argv) == 1: release = get_release()