Skip to content

Installing siptrackweb in virtualenv

Stefan Midjich edited this page Mar 7, 2018 · 39 revisions

If you find this guide unmaintained then check out the ansible roles siptrack-backend and siptrack-frontend.


How to install siptrackd in virtualenv

This how you setup your own self-hosted version of Siptrack.

This guide is last tested on Fedora 23 and CentOS 7. Here is a shorter guide for a personal dev environment.

It is assumed you have a user called siptrack, and a group called virtualenv.

$ sudo groupadd virtualenv
$ sudo useradd -r -G virtualenv siptrack

Prepare system

This differs on Debian, here are RHEL-based distros commands.

$ sudo yum install openssl-devel gcc libffi-devel mariadb mariadb-devel pwgen

Setup virtualenv

$ sudo mkdir -p /var/opt/venv
$ sudo chgrp -R virtualenv /var/opt/venv
$ sudo chmod -R 2775 /var/opt/venv

Join yourself to virtualenv and siptrack group for ease of administration. Then you can even create the virtualenv without sudo.

$ virtualenv /var/opt/venv/siptrack

Enter virtualenv for the rest of the installation.

$ . /var/opt/venv/siptrack/bin/activate

Install dependencies in virtualenv.

$ pip install textile Twisted pyOpenSSL python-ldap Django gunicorn Whoosh pycrypto

Install siptrackd and siptrackweb

Clone git repos.

$ sudo mkdir /var/opt/siptrack
$ sudo chgrp -R virtualenv /var/opt/siptrack
$ sudo chmod -R 2775 /var/opt/siptrack
$ cd /var/opt/siptrack
$ git clone https://github.com/sii/siptrackd.git # Background API daemon
$ git clone https://github.com/sii/siptrackweb.git # Web GUI
$ git clone https://github.com/sii/siptrack.git # Client tools and library

Enter the cloned git repository and install.

$ cd siptrack
$ python setup.py install
$ cd ..

$ cd siptrackd
$ python setup.py install
$ cd ..

$ cd siptrackweb
$ python setup.py install
$ cd ..

Configure siptrackd

Here is an example systemd unit for siptrackd, change paths to correspond with your install. Set ConditionPathExists to wherever you installed siptrackd.

[Unit]
Description=Siptrackd - Inventory management backend server
ConditionPathExists=/var/opt/siptrack/siptrackd
After=network.target

[Service]
Type=simple
User=siptrack
Group=virtualenv
EnvironmentFile=/etc/sysconfig/siptrackd
ExecStart=/bin/bash -c "source $SIPTRACKD_VENVDIR/bin/activate; $SIPTRACKD_VENVDIR/bin/siptrackd $SIPTRACKD_ARGS"
SyslogIdentifier=siptrackd

[Install]
WantedBy=multi-user.target

Make sure to also create the EnvironmentFile /etc/sysconfig/siptrackd with the virtualenv path.

SIPTRACKD_VENVDIR=/var/opt/venv/siptrack
SIPTRACKD_ARGS=-l - -b stsqlite -s /etc/siptrackd_storage.cfg --searcher=whoosh --searcher-args=/tmp/st-whoosh
PYTHONPATH=/var/opt/siptrack/siptrackd

Also copy the sample storage configuration from /var/opt/siptrack/siptrackd/storage.cfg into /etc as shown in SIPTRACKD_ARGS above. Make sure its permissions aren't readable by world.

Enable and start in systemd.

$ sudo systemctl daemon-reload
$ sudo systemctl enable siptrackd
$ sudo systemctl start siptrackd

Follow logs with journalctl -flau siptrackd.

Configure siptrackweb

$ sudo mkdir /var/www/siptrackweb
$ sudo chown -R siptrack:virtualenv /var/www/siptrackweb
$ sudo chmod -R 2775 /var/www/siptrackweb
$ cd /var/www/siptrackweb
$ django-admin startproject stweb
$ cd stweb

Open the file stweb/settings.py and edit the following values.

SIPTRACK_SERVER = 'localhost'
SIPTRACK_USE_SSL = False
ADMINS = (
    '[email protected]'
)
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'siptrackweb'
TIME_ZONE = 'Europe/Copenhagen'

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'siptrackweb',
)

Also remove the line about CSRF middleware from MIDDLEWARE_CLASSES.

MIDDLEWARE_CLASSES = (
...
    #'django.middleware.csrf.CsrfViewMiddleware',
...
)

Then edit stweb/urls.py so it contains the following.

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'', include('siptrackweb.urls')),
]

Now generate the database and an admin user.

$ python manage.py migrate

Install supervisord and configure gunicorn

Install supervisord on CentOS.

$ sudo yum install supervisor

Enable and start supervisor service on CentOS.

$ sudo systemctl enable supervisord
$ sudo systemctl start supervisord

Configure gunicorn in supervisor

Create the file /etc/supervisor.d/siptrackweb.ini on CentOS. File path might differ on Debian-based systems.

[program:siptrackweb]
command=/var/opt/venv/siptrack/bin/gunicorn stweb.wsgi --workers 3 --log-level DEBUG --bind localhost:8080
directory=/var/www/siptrackweb/stweb
pythonpath=/var/opt/venv/siptrack/lib/python2.7/site-packages
user=siptrack
group=virtualenv
umask=002
autostart=true
autorestart=true
stdout_logfile=/var/log/gunicorn_siptrackweb.log
loglevel=debug
redirect_stderr=true
stopsignal=QUIT
environment=PATH=/var/opt/venv/siptrack/bin

Start siptrackweb.

$ sudo supervisorctl start siptrackweb

Configure nginx

Copy static files into /var/www.

$ sudo cp -r /var/opt/venv/siptrack/lib/python2.7/site-packages/siptrackweb/static /var/www/siptrackweb/

Here is a sample nginx configuration.

server {
  listen 80;
  server_name siptrack.localhost;

  location / {
    add_header X-Clacks-Overhead "GNU Terry Pratchett";
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    location /static/ {
      alias /var/www/siptrackweb/static/;
    }

    # if using ssl set this
    # proxy_set_header X-Forwarded-Proto https;

    if (!-f $request_filename) {
      proxy_pass http://localhost:8080;
      break;
    }
  }
}

Restart nginx and browse to the domain you configured for siptrack, login with admin:admin.

SELinux

Enable httpd service to connect to the backend.

$ sudo setsebool -P httpd_can_network_connect=on

Reinstall

Note on reinstalling, if you get weird permission errors that you can't explain it might be good to just start over. Shutdown all services and delete all dirs.

$ cd /var/opt/siptrack
$ sudo systemctl stop nginx && sudo systemctl stop supervisord && sudo systemctl stop siptrackd
$ sudo rm -rf siptrackweb siptrackd /var/www/siptrackweb /var/opt/venv

And do the guide over again but skipping the user and group creation.

Whoosh locking Exception

This might happen at startup of Siptrackd but just restart the service and it should be resolved.