From d3b30a10018142bce02f6b1870125225f6a42f9b Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 2 Jul 2017 16:00:58 +0300 Subject: Add: uWSGI, systemd integration, incl. in .deb --- debian/control | 2 +- debian/ick2.dirs | 1 + debian/ick2.install | 2 ++ debian/ick2.postinst | 8 ++++++++ ick2-controller | 38 ++++++++++++++++++++++++++++++++++++++ ick2.service | 14 ++++++++++++++ ick2lib/apiservice.py | 3 +++ setup.py | 2 +- uwsgi.ini | 12 ++++++++++++ 9 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 debian/ick2.dirs create mode 100644 debian/ick2.install create mode 100644 debian/ick2.postinst create mode 100644 ick2-controller create mode 100644 ick2.service create mode 100644 uwsgi.ini diff --git a/debian/control b/debian/control index 19c4fda..c4e5b06 100644 --- a/debian/control +++ b/debian/control @@ -11,6 +11,6 @@ X-Python-Version: >= 2.7 Package: ick2 Architecture: all Depends: ${python:Depends}, ${misc:Depends}, python (>= 2.7), - python-bottle, python-cliapp + python-bottle, python-cliapp, uwsgi-plugin-python Description: a work-in-progress CI server This should be written. diff --git a/debian/ick2.dirs b/debian/ick2.dirs new file mode 100644 index 0000000..7bcc774 --- /dev/null +++ b/debian/ick2.dirs @@ -0,0 +1 @@ +var/lib/ick2 diff --git a/debian/ick2.install b/debian/ick2.install new file mode 100644 index 0000000..49189b5 --- /dev/null +++ b/debian/ick2.install @@ -0,0 +1,2 @@ +uwsgi.ini etc/ick2 +ick2.service lib/systemd/system diff --git a/debian/ick2.postinst b/debian/ick2.postinst new file mode 100644 index 0000000..b429951 --- /dev/null +++ b/debian/ick2.postinst @@ -0,0 +1,8 @@ +#!/bin/sh + +set -eu + +# Create the log directory with the right ownership and permissions. +install -d -m 0755 -o www-data -g www-data /var/log/ick2 + +#DEBHELPER# diff --git a/ick2-controller b/ick2-controller new file mode 100644 index 0000000..91b593b --- /dev/null +++ b/ick2-controller @@ -0,0 +1,38 @@ +#!/usr/bin/env python2 + + +import argparse +import logging +import sys + +import yaml + +import ick2lib + + +def load_projects(filename): + with open(filename) as f: + projects_config = yaml.safe_load(f) + + projects = {} + for name, config in projects_config['projects'].items(): + p = ick2lib.Project(name) + projects[name] = p + for shell in config['shell_steps']: + p.add_build_step(shell) + + return projects + + +parser = argparse.ArgumentParser() +parser.add_argument('--projects', action='store', dest='projects') +parser.add_argument('--log', action='store', dest='log', default='/dev/null') +results = parser.parse_args() + +logging.basicConfig(filename=results.log, level=logging.DEBUG) + +logging.info('ick2-controller starts') +projects = load_projects(results.projects) +service = ick2lib.ApiService() +service.set_projects(projects) +application = service.get_uwsgi_app() diff --git a/ick2.service b/ick2.service new file mode 100644 index 0000000..1c458ac --- /dev/null +++ b/ick2.service @@ -0,0 +1,14 @@ +[Unit] +Description=uWSGI instance to serve Ick2 controller +After=network.target + +[Service] +Type=simple +User=www-data +Group=www-data +WorkingDirectory=/var/lib/ick2 +ExecStart=/usr/bin/uwsgi --ini /etc/ick2/uwsgi.ini +KillSignal=QUIT + +[Install] +WantedBy=multi-user.target diff --git a/ick2lib/apiservice.py b/ick2lib/apiservice.py index 363f3c0..e4cfe8a 100644 --- a/ick2lib/apiservice.py +++ b/ick2lib/apiservice.py @@ -122,6 +122,9 @@ class ApiService(object): def set_projects(self, projects): self._projects = projects + def get_uwsgi_app(self): + return self._app + def run_debug(self, port): self._app.run(port=port, quiet=True) diff --git a/setup.py b/setup.py index c7c8300..cc1b631 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ setup( author='Lars Wirzenius', author_email='liw@liw.fi', url='http://liw.fi/ick/', - scripts=['controller'], + scripts=['ick2-controller'], packages=['ick2lib'], data_files=[], ) diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 0000000..2a427c4 --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,12 @@ +[uwsgi] +logger = python +http-socket = 0.0.0.0:12765 +master = true +plugins = python +wsgi-file = /usr/bin/ick2-controller +pyargv=--projects /etc/ick2/projects.yaml --log /var/log/ick2/ick2.log +uid = www-data +gid = www-data +workers = 1 +threads = 1 +buffer-size = 32768 -- cgit v1.2.1