Here's a collection of scripts/logs/etc related to deploying a simple twilio flask application onto an apache2 webserver hosted on AWS. Running the flask script on its own everything works as expected, but trying to have apache2 run it results in the site not working, but also no errors being generated.
It seems like everything should be working, but maybe there's something that's been overlooked?
In our var folder we have:
ubuntu@ip-10-0-0-227:/var/www/sub.site.com$ ls -l
total 16
-rwxr-xr-x 1 root root 115 Oct 2 16:02 sub.site.com.wsgi
-rw-r--r-- 1 root root 15 Oct 2 14:30 knownStores.txt
-rwxrwxr-x 1 root root 1461 Oct 2 16:00 twilioWorker.py
The wsgi script looks like:
ubuntu@ip-10-0-0-227:/var/www/sub.site.com$ cat sub.site.com.wsgi
#!/usr/bin/python
import sys
sys.path.insert(0,"/var/www/sub.site.com")
from twilioWorker import application
For the conf file:
ubuntu@ip-10-0-0-227:/etc/apache2/sites-available$ cat sub.site.com.conf
<VirtualHost *:80>
ServerName sub.site.com
ServerAdmin eng@company.com
WSGIScriptAlias / /var/www/http://ift.tt/1JKfI5z
<Directory /var/www/sub.site.com/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
After restarting the server (with sudo) and going to the site this is what the apache error log contains:
[Fri Oct 02 16:33:24.015980 2015] [mpm_prefork:notice] [pid 13904] AH00171: Graceful restart requested, doing restart
[Fri Oct 02 16:33:24.100702 2015] [mpm_prefork:notice] [pid 13904] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.12 mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Fri Oct 02 16:33:24.100713 2015] [core:notice] [pid 13904] AH00094: Command line: '/usr/sbin/apache2'
[Fri Oct 02 16:33:26.810365 2015] [mpm_prefork:notice] [pid 13904] AH00169: caught SIGTERM, shutting down
[Fri Oct 02 16:33:27.810362 2015] [mpm_prefork:notice] [pid 14072] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.12 mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Fri Oct 02 16:33:27.810402 2015] [core:notice] [pid 14072] AH00094: Command line: '/usr/sbin/apache2'
[Fri Oct 02 16:33:34.730875 2015] [:info] [pid 14077] [client xxx.xxx.xxx.xxx:58189] mod_wsgi (pid=14077, process='', application='sub.site.com|'): Loading WSGI script '/var/www/http://ift.tt/1JKfI5z'.
Finally the full python script is:
from flask import Flask, request, redirect
import twilio.twiml
import MySQLdb
def readStoreFile( fName):
stores = []
with open( fName, "rb") as myFile:
for line in myFile:
stores.append(line.strip())
return stores[:]
storeText = "/var/www/http://ift.tt/1P9ujhV"
myStores = readStoreFile(storeText)
conn = MySQLdb.connect("localhost","user","password","db")
myConn = conn.cursor()
application = Flask(__name__)
@application.route("/", methods=['GET', 'POST'])
def hello_monkey():
"""Respond to incoming calls with a simple text message."""
resp = twilio.twiml.Response()
msgIn = request.values.get("Body",None).strip()
whoFrom = request.values.get("From",None).replace("+","").strip()
msgOut = ""
if msgIn in myStores:
msgOut = "Thank you for selecting company!\nWe are happy that you visited!\n"
msgOut += "Please visit the following site for your new app\n"
msgOut += "http://ift.tt/1JKfI5B"+msgIn+"&phoneId="+whoFrom
else:
msgOut = "Thank you for selecting company!\nWe are happy that you visited!\n"
msgOut += "Please visit the following site for your new app\n"
msgOut += "http://ift.tt/1P9uklR"+whoFrom
resp.message(msgOut)
try:
myConn.execute("""insert into numbers (number) values (%s)""",(whoFrom))
conn.commit()
except:
conn.rollback()
return str(resp)
if __name__ == "__main__":
application.run()
One thing we've found is that running the python script on its own $sudo netstat -tlp will show python listening on port 5000. However, when reload/restart-ing apache this doens't show up. Is there an obvious reason this combination of scripts/actions isn't working?
Aucun commentaire:
Enregistrer un commentaire