Business and Technology

Web 2.0, Business, PHP, MySQL, CodeIgniter, Volkan Rivera’s Blog

Posts Comments



Category: Google

Setting up your own GAE server

19 May, 2008 (09:34) | Internet, OpenSource, Google | By: volkan68

The newest service of Google that has drawn my attention in recent months is GAE (Google App Engine), which allows us to use the Google’s network to deploy our web application in a transparent manner and win the ability to withstand million hits a day and to have our data replicated. Solving two serious problems facing all Start-up of the Information Technology Industry, scalability and high availability.

The main problem now with GAE, which is in beta right now, is that it is just available by invitation from Google. Fortunately I have one of this invitations accounts, but I began to think of all those who wish to test the service and currently do not have an GAE account . Even if I would  be generous, Google does not allow more than three projects in GAE right now, and I can not erase projects, so until I have to be careful with my three projects.

So what can we do? Well, Google now offers as part of the SDK of GAE a very simple webserver which allows us to test our GAE application in our own machine, the problem is that by default the script dev_appserver.py only listen on localhost on port 8080. I thought about it, and after play around with the settings, I got a configuration that works using public IP and port 80, now I have that kind of solution running on http://gae.volkanrivera.com

It is important to be aware that not all features are supported by the GAE dev_appserver.py, the most important lack is the ability of logging using a Google Account. Please note that this type of solution I present here is a bit risky so I recommend you do it on a virtual server that can simply shut down in case of problems (someone hack the dev_appserver.py and our server is used to send spam). Let’s start with the configuration, as root user install these packages:
 
# apt-get install g++ zip unzip less postfix proftpd pound

If necessary you can reconfigure the postfix using this command:
 
# dpkg-reconfigure postfix

When asked about what type of service you want for proftpd, select "standalone". Then edit /etc/proftpd/proftpd.conf and add these lines:

TimesGMT off
DefaultRoot ~

Do it after these line:

# Port 21 is the standard FTP port.
Port 21

Additionally disable the protocol ipv6 in /etc/proftpd/proftpd.conf this way:

UseIPv6 off

Now we edit the configuration file of the reverse proxy at /etc/pound/pound.cfg Just let these lines, be careful to replace www.xxx.yyy.zzz by the public IP of your server:

User            "www-data"
Group           "www-data"
LogLevel        1
## check backend every X secs:
Alive           30

ListenHTTP
        Address www.xxx.yyy.zzz
        Port    80

        xHTTP           0

        Service
                BackEnd
                        Address 127.0.0.1
                        Port    8080
                End
        End
End

Then edit /etc/default/pound and place the value of variable startup = 1 Now we install the SDK, in order to do it, we have to download and install it as root user, in this way:

# cd /usr/src # wget http://googleappengine.googlecode.com/files/google_appengine_1.0.2.zip
# unzip google_appengine_1.0.2.zip
# mv google_appengine /usr/local/gae


Now that we have installed our SDK we proceed to create a user who will run the GAE webserver in our case we will use the username "gae", but it can be anyone:

# adduser gae

Finally we change the user "gae" and continue the rest of the configuration as "gae" user:

$ cd ~/
$ cp -R /usr/local/gae/demos/guestbook/ ./


We need to create two scripts one to start the GAE server and another to stop it, here the script to start up the dev_appserver.py, you can call it "start_gae":

#!/bin/bash

/usr/local/gae/dev_appserver.py
–enable_sendmail
$1
2>~/gae.log &


Here is the script to stop it, you can call it "stop_gae":

#!/bin/bash

kill -9 `lsof -i :8080 | grep ^python | awk ‘{print $2}’`

Before starting the server GAE, we need to create the following files, we’ll do with the same user that will run GAE webserver, to do so we use these commands:

$touch /tmp/dev_appserver.datastore
$touch /tmp/dev_appserver.datastore.history


If you do not have privileges to create these files as user "gae", simply change to "root" user create them, and then change the owner with the chown command to user "gae". Now we are ready to start the GAE server, which for the moment we use to run the demo application that comes within the SDK call "guestbook", to do so as the user "gae" execute this command:

$ ./start_gae guestbook/

If you have done all well. You should obtain this as the result of a "netstat-tl":

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:webcache      *:*                     LISTEN
tcp        0      0 *:ftp                   *:*                     LISTEN
tcp6       0      0 *:ssh                   *:*                     LISTEN
tcp6       0      0 *:smtp                  *:*                     LISTEN


Note that "webcache" is the name of the port 8080. Now as the "root" user we must initiate the reverse proxy, to do so we use this command:

# /etc/rc.d/pound start

Ready now we can see our guessbook simply pointing to the IP public or using a valid domain name pointed to the IP. Enjoy your own GAE server, and happy coding.