Running multiple services using dev_appserver.py on different ports

1.8k views Asked by At

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 )

1

There are 1 answers

2
Dan Cornilescu On

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