Skip to content
Permalink
Browse files

- Added logging to gunicorn

- Switched to gunicorn's built-in PID reporting
- Fixed bug in sleep SECONDS restart delay
- Moved MySQL loading from __name__ block to top within flaskr.py
  • Loading branch information...
jeffseif committed Jan 31, 2014
1 parent 8510c50 commit b05ead02deb45909216ec23967e10cd932d501d6
Showing with 28 additions and 20 deletions.
  1. +1 −1 check.sh
  2. +14 −9 host.sh
  3. +13 −10 static/py/flaskr.py
@@ -2,4 +2,4 @@

PID="$(cat ~/log/pid)" ;

ps -p "${PID}" > /dev/null && echo 'Up' || echo 'Down' ;
[ -e "${PID}" ] && echo 'Up' || echo 'Down' ;
23 host.sh
@@ -5,30 +5,35 @@
###
APP='flaskr:app' ;
DIR='../log/' ;
GUNICORN="sudo gunicorn ${APP} -w 4 -b 0.0.0.0:80" ;
SECONDS='5' ;
IPADDRESS='0.0.0.0:80' ;
RESTARTSECONDS='5' ;
NUMWORKERS='1' ;
PID="${DIR}pid" ;
TIMEOUTSECONDS='300' ;

###
# Declare PID
# gunicorn command
###
PID="${DIR}pid" ;
\rm -f "${PID}" ;
echo "$$" > "${PID}" ;
GUNICORN="sudo gunicorn ${APP} -w ${NUMWORKERS} -b ${IPADDRESS} -p ${PID} --access-logfile - --error-logfile - --timeout ${TIMEOUTSECONDS}" ;

###
# Host
###
while [ 0 ] ; do
###
# Set log filename
# Set log/err filename
###
LOG="${DIR}$(date "+%F-%T").log" ;
ERR="${DIR}$(date "+%F-%T").err" ;
###
# Execute gunicorn
###
${GUNICORN} >> "${LOG}" 2>&1 ;
echo "Starting gunicorn and dumping log to ${LOG}" ;
${GUNICORN} >> "${LOG}" 2>> "${ERR}" ;
###
# Upon fail wait before looping
###
sleep "${SECONDS}" ;
echo "gunicorn finished ... sleeping for ${RESTARTSECONDS}s ..." ;
sleep "${RESTARTSECONDS}" ;
echo "... restarting now" ;
done ;
@@ -14,7 +14,19 @@
### Initialize
###

###
# Flask
###
app = Flask(__name__);
###
# Build graph
###
id2Node, id2Edge, id2Poi, id2Tree, graphIds = dogWalkScore.MySql2Graph();
###
# Create global croppedIds
###
global croppedIds;
croppedIds = [];

###
### Flask routing
@@ -84,15 +96,6 @@ def other():

if __name__ == '__main__':
###
# Build graph
###
id2Node, id2Edge, id2Poi, id2Tree, graphIds = dogWalkScore.MySql2Graph();
###
# Create global croppedIds
###
global croppedIds;
croppedIds = [];
###
# Run Flask
# Run Flask in debug, port 8000
###
app.run(debug = True, port = 5000, host = '0.0.0.0');

0 comments on commit b05ead0

Please sign in to comment.
You can’t perform that action at this time.