Reputation: 79
I try to deploy a tornado by myself on openshift diy cartridges but meet some problem.
I have installed python 2.7.6 and tornado 3.2, and tried to run the tornado hello world demo on it. But it always went error. In addition, I have executed the chmod 777 instruction for $OPENSHIFT_REPO_DIR/diy.
Here followings are what I did and the error logs. How can I solve this problem and start my application?
This file named start.py is the only file in $OPENSHIFT_REPO_DIR/diy.
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8080)
tornado.ioloop.IOLoop.instance().start()
start:
nohup $OPENSHIFT_DATA_DIR/bin/python $OPENSHIFT_REPO_DIR/diy/start.py > $OPENSHIFT_DIY_LOG_DIR/tornado_server.log 2>&1 &
stop:
source $OPENSHIFT_CARTRIDGE_SDK_BASH
if [ -z "$(ps -ef | grep start.py | grep -v grep)" ]
then
client_result "Application is already stopped"
else
kill `ps -ef | grep start.py | grep -v grep | awk '{ print $2 }'`
> /dev/null 2>&1
fi
Traceback (most recent call last):
File ".../app-root/runtime/repo//diy/start.py",
line 13, in <module>
application.listen(8080)
File ".../app-root/data/lib/python2.7/site-packages/tornado/web.py",
line 1559, in listen
server.listen(port, address)
File ".../app-root/data/lib/python2.7/site-packages/tornado/tcpserver.py",
line 117, in listen
sockets = bind_sockets(port, address=address)
File ".../app-root/data/lib/python2.7/site-packages/tornado/netutil.py",
line 104, in bind_sockets
sock.bind(sockaddr)
File ".../app-root/data/lib/python2.7/socket.py",
line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied
Upvotes: 1
Views: 713
Reputation: 9636
You do not have to use DIY cartridge to deploy Tornado on Openshift.
check this repo for example: https://github.com/avinassh/openshift-tornado-starter
Upvotes: 1
Reputation: 5931
This will not work because you have to bind to $OPENSHIFT_DIY_IP and $OPENSHIFT_DIY_PORT. Instead of application.listen(8080)
use following code
ip = os.environ['OPENSHIFT_DIY_IP']
port = int(os.environ['OPENSHIFT_DIY_PORT'])
application.listen(port , ip)
Also, I have written a blog that could help you https://www.openshift.com/blogs/day-25-tornado-combining-tornado-mongodb-and-angularjs-to-build-an-app
Upvotes: 2