在不同的端口上使用dev_appserver.py运行多个服务 [英] Running multiple services using dev_appserver.py on different ports

查看:208
本文介绍了在不同的端口上使用dev_appserver.py运行多个服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想使用dev_appserver.py在本地运行REST和WEB服务

我有一个应用程序,它有休息终点和web终点。

我已经尝试了以下内容:

$ p $ dev_appserver.py rest_app.yaml --port = 5010 - admin_port = 8000



dev_appserver.py web_app.yaml --port = 5011 --admin_port = 8001 $ b

我在其中一个服务(休息服务)上看到以下错误:

 `OperationalError:database is locked` 

我需要做什么特别的以确保这些服务可以在没有任何条件(或类似的坏事情)的情况下读/写共享数据库。



我的目标是运行多个服务(休息和网站在这种情况下)在本地和这些服务应该数据。什么是最好的方式来做到这一点(本地使用dev_appserver.py)和GAE本身(当我将应用程序推送到GAE时,这会晚一些:D)

解决方案

你得到 OperationalError:database is locked 的原因是2 dev_appserver.py code>实例会碰撞试图访问同一个数据库本地存储目录,默认情况下是根据应用程序的名称确定的 - 对同一应用程序的2个服务是相同的。



避免这种冲突的一种方法是使用 dev_appserver.py - storage_path 可选参数(您可以通过 dev_appserver.py --help 来查看):

   -  storage_path PATH与应用程序关联的数据(数据存储区,blobstore等)
的路径。 (默认值:无)

然而,使用2种不同的存储路径可能会产生意想不到的结果 - 应该是该存储中的相同信息,他们可能会看到不同的值。



正确使用 dev_appserver.py 同一应用程序的多个服务是通过一个 dev_appserver.py 实例运行所有服务,该实例将为每个服务分配不同的端口。



例如,我有一个包含3个服务的应用程序,并使用一个调度文件。这是我从应用程序目录调用开发服务器的方法,这是3个服务目录的父目录(调度文件必须是 .yaml 列表中的第一个)文件参数,我总是遵循它与默认模块的一个,在我的情况下 main / main.yaml ):

  /usr/bin/python2.7 /usr/local/google_appengine/dev_appserver.py --host 0.0.0.0 --log_level = debug dispatch.yaml main / main.yaml buildin / buildin .yaml apartci / apartci.yaml 

这就是devserver自动分配每个服务侦听的端口的方式,在服务器启动时显示:

  INFO 2016-11-18 14:20:53,329 api_server.py:205]启动API服务器:http:// localhost:40310 
INFO 2016-11-18 14:20:53,330 dispatcher.py:185]开始运行的分派器:http://0.0.0.0:8080
INFO 2016-11-18 14:20:53,345 dispatcher.py:197]启动模块default运行于:http://0.0.0.0:8081
INFO 2016-11-18 14:20:53,353 dispatcher.py:197]启动模块buildin运行于:http://0.0.0.0:8082
INFO 2016-11-18 14:20:53,361 dispatcher.py:197]启动模块apartci运行在:http://0.0.0.0:8083
INFO 2016-11-18 14:20:53,362 admin_server.py:116]启动管理服务器:http:// localhost:8000


I have an application which has rest end point and web end point.

I want to run both REST and WEB service locally using dev_appserver.py

I have tried the following

dev_appserver.py rest_app.yaml --port=5010 --admin_port=8000

dev_appserver.py web_app.yaml --port=5011 --admin_port=8001

I see the following error on one of my services (rest service)

`OperationalError: database is locked`

Do I have to do anything special to make sure both those services can read/write to a shared database without any conditions (or similar bad things !!)

My goal is to run multiple services (rest and web in this case) locally and those services should data. What is the best way to do this (using dev_appserver.py locally) and in GAE itself (this will come later when I push my application to GAE :D )

解决方案

The reason for which you're getting OperationalError: database is locked is that the 2 dev_appserver.py instances will collide trying to access the same database local storage dir, which by default is determined based on the app's name - identical for 2 services of the same app.

One way to avoid such collision is to also specify the local storage directory, using dev_appserver.py's --storage_path optional argument (which you can see via dev_appserver.py --help):

--storage_path PATH   path to the data (datastore, blobstore, etc.)
                      associated with the application. (default: None)

However using 2 different storage paths may produce unexpected results - if your services reference what should be the same information in that storage they might see different values.

The proper way of using dev_appserver.py with multiple services of the same app is to run all the services through a single dev_appserver.py instance, which will allocate different ports to each service.

For example I have an app with 3 services and using a dispatch file. This is how I invoke the dev server, from the app dir which is the parent dir of 3 service dirs (the dispatch file must be the 1st one in the list of .yaml file args and I always follow it with the default module's one, in my case main/main.yaml):

/usr/bin/python2.7 /usr/local/google_appengine/dev_appserver.py --host 0.0.0.0 --log_level=debug dispatch.yaml main/main.yaml buildin/buildin.yaml apartci/apartci.yaml

And this is how the devserver automatically assigns the ports each service listens to, displayed when the server starts:

INFO     2016-11-18 14:20:53,329 api_server.py:205] Starting API server at: http://localhost:40310
INFO     2016-11-18 14:20:53,330 dispatcher.py:185] Starting dispatcher running at: http://0.0.0.0:8080
INFO     2016-11-18 14:20:53,345 dispatcher.py:197] Starting module "default" running at: http://0.0.0.0:8081
INFO     2016-11-18 14:20:53,353 dispatcher.py:197] Starting module "buildin" running at: http://0.0.0.0:8082
INFO     2016-11-18 14:20:53,361 dispatcher.py:197] Starting module "apartci" running at: http://0.0.0.0:8083
INFO     2016-11-18 14:20:53,362 admin_server.py:116] Starting admin server at: http://localhost:8000

这篇关于在不同的端口上使用dev_appserver.py运行多个服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆