diff --git a/virtual-metro.service b/virtual-metro.service index 59ebb97..3b0924d 100644 --- a/virtual-metro.service +++ b/virtual-metro.service @@ -4,7 +4,7 @@ After=network.target [Service] WorkingDirectory=/opt/virtual-metro -ExecStart=/usr/bin/gunicorn -w 4 -b 127.0.0.1:8111 virtual_metro:app +ExecStart=/usr/bin/gunicorn -w 4 -b 127.0.0.1:8111 --preload virtual_metro:app User=vmetro Group=vmetro diff --git a/virtual_metro/__init__.py b/virtual_metro/__init__.py index cf35028..0fbe25d 100755 --- a/virtual_metro/__init__.py +++ b/virtual_metro/__init__.py @@ -138,8 +138,7 @@ def latest(): # Cache list of stations stns = None -@app.route('/stations') -def stations(): +def get_station_list(): global stns if not stns: stn_list = {} @@ -152,5 +151,11 @@ def stations(): stns = [(k, v) for k, v in stn_list.items()] stns.sort(key=lambda x: x[1]) - + +if not app.debug: + get_station_list() + +@app.route('/stations') +def stations(): + get_station_list() return flask.render_template('stations.html', stations=stns)