Skip to content

Setting up a production server

SushiTee edited this page Jul 20, 2013 · 12 revisions

Setting up a production server

A production server is a server for use.
The following manual shows how to install upTee on a linux server using nginx and uWSGI.

Installation

###Install all requirements Be sure to install all requirements shown in the Home page.
Do not install uWSGI yet!
In case the command pip is not available after installing setuptools run the following command:

$ easy_install pip

  1. Create a new user and be sure to make him the owner of the virtualenv which will be created in the next step.

      In this manual the user uptee is used!

  2. Create a virtualenv. This will house a complete Python environment, and the compiled uwsgi binary.

$ easy_install virtualenv
$ virtualenv uptee
$ cd uptee/
$ . bin/activate

  3. Download the uWSGI tarball into a pkg/ directory.

$ mkdir pkg && cd pkg/
$ wget 'http://projects.unbit.it/downloads/uwsgi-latest.tar.gz'

  4. Compile uWSGI. You may have to install missing packages to compile uWSGI.

$ tar -xzvf uwsgi-latest.tar.gz
$ cd uwsgi-*/
$ make

      The last command creates the uwsgi binary which must be moved to the bin folder.

$ mv uwsgi $VIRTUAL_ENV/bin/uwsgi

###Configuration

  1. Clone upTee

$ cd $VIRTUAL_ENV
$ git clone git://github.com/upTee/upTee.git web

  2. Install all requirements

      Switch into the web directory and run the following command:

$ pip install -r requirements.txt
$ pip install -r requirements_production.txt

      If an error appears install the missing packages. The error messages are obvious.
      In windows download packages which fails from here.
      Repeat the command until the installation finishes successfully!
      If there are still problems with some modules have a look at the Troubleshooting section at the end of this page.

  3. Set up the website

      Switch into the uptee directory.
      To set up the project copy the settings_local.py.example and rename the new file to settings_local.py.
      Now edit the settings how u like. You can find an example for a production server here.
      Copy browscap.csv.example and rename the new file to browscap.csv.

  4. Install the database

$ python manage.py syncdb

      It will ask to create a Superuser. Do not do that!

$ python manage.py migrate

      Now create the Superuser.

$ python manage.py createsuperuser

  5. Set up the port map

      The port map is a list of available ports for the teeworlds servers. Be sure that the ports are not blocked by a firewall.

$ python manage.py create_portmap 8300 8320

      This command adds the ports 8300 till 8320 to upTee. Decide yourself which ports you want to use and how many you need.

  6. Link static admin_tools files

      The static admin_tools files are devided over more than one folder which will cause problems. Thats why we simply link them in one server.

$ $VIRTUAL_ENV/web/scripts/admin_tool_statics

  7. Set up nginx

      Create the sock folder.

mkdir $VIRTUAL_ENV/sock

      Open the nginx config file and add the following code to the http section:

# uWSGI serving Django.
upstream django {
	# Distribute requests to servers based on client IP. This keeps load
	# balancing fair but consistent per-client. In this instance we're
	# only using one uWGSI worker anyway.
	ip_hash;
	server unix:/path/to/virtualenv/sock/uwsgi.sock;
}

server {
	listen 80;
	server_name example.org www.example.org; # your domain here!

	# Django admin media.
	location /media/admin/ {
		alias /path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/static/admin/;
	}

	# Django admin static.
	location /static/admin/ {
		alias /path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/static/admin/;
	}

	# Django admin_tools static.
	location /static/admin_tools/ {
		alias /path/to/virtualenv/lib/python2.7/site-packages/admin_tools/static/admin_tools/;
	}

	# Your project's media directory.
	location /media/ {
		alias /path/to/virtualenv/web/uptee/media/;
	}

	# Your project's static directory.
	location /static/ {
		alias /path/to/virtualenv/web/uptee/static/;
	}

	# Finally, send all non-media requests to the Django server.
	location / {
		# touch /path/to/virtualenv/web/downtime to set the page down
		if (-f /path/to/virtualenv/web/downtime) {
			return 503;
		}

		uwsgi_pass  django;
		include     uwsgi_params;
		uwsgi_read_timeout 1800;
	}

	error_page 502 503 504 @maintenance;
	location @maintenance {
		root /path/to/virtualenv/web/uptee/templates/;
		rewrite ^(.*)$ /502.html break;    
	}
}

      Be sure to change the path to the virtualenv and put your own domain.
      To finish the nginx configuration restart nginx:

$ /etc/init.d/nginx restart

###Start up everything Starting up everything means to run some processes. There are scripts to make everything easy.

  1. Create the log directory

mkdir -p $VIRTUAL_ENV/var/log

  2. Get the scripts

      Download the start script and copy into the virtualenv directory.
      Download the uptee script and copy into the virtualenv directory.
      Download the uptee init.d script and copy into /etc/init.d/.

  3. Edit the scripts

      Open every script and change the path to the actual virtualenv directory.
      Be sure every script is executable!

  4. Activate the init.d script

$ update-rc.d uptee defaults

  5. Start upTee

$ /etc/init.d/uptee start

###Miscellaneous The init.d script allows it to start/stop/restart upTee.

$ /etc/init.d/uptee {start|stop|restart}

To update uptee simply update the git repository.

$ git pull origin master

After updating the website needs to be restarted to make the changes take effect!

Troubleshooting

###captcha is not working For the captcha to work it is needed to install PIL with freetype and PNG support.

$ sudo apt-get install libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev
$ pip install PIL