Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install docs updated to jessie and stretch #246

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ python:
services:
- elasticsearch

env:
- VERSION_GEVENT="1.0.1"
- VERSION_GEVENT="1.0.2"
- VERSION_GEVENT="1.1.0"

before_install:
- pip install --force gevent==$VERSION_GEVENT


install:
- "pip install flake8 sphinx"
- "python setup.py install"
- pip install flake8 sphinx
- python setup.py install

before_script:
- sleep 10 # wait for elasticsearch

script:
- 'flake8'
- flake8
- python setup.py test
- "python setup.py build_sphinx"
- python setup.py build_sphinx
2 changes: 1 addition & 1 deletion cli/agherant.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def agherant(settings, debug, port, address, agherant_descriptions):
if agherant_descriptions:
cliConf['AGHERANT_DESCRIPTIONS'] = agherant_descriptions
conf.update(cliConf)
initLoggers(logging.DEBUG if conf.get('DEBUG', False) else logging.WARNING)
initLoggers(logging.DEBUG if conf.get('DEBUG', False) else logging.INFO)
try:
main(conf)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion cli/libreant.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def libreant(settings, debug, port, address, fsdb_path, es_indexname, es_hosts,
click.echo(json.dumps(conf, indent=3))
exit(0)

initLoggers(logging.DEBUG if conf.get('DEBUG', False) else logging.WARNING)
initLoggers(logging.DEBUG if conf.get('DEBUG', False) else logging.INFO)
try:
main(conf)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion cli/libreant_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def libreant_db(debug, settings, fsdb_path, es_indexname, es_hosts):
if es_hosts:
cliConf['ES_HOSTS'] = es_hosts
conf.update(cliConf)
initLoggers(logging.DEBUG if conf.get('DEBUG', False) else logging.WARNING)
initLoggers(logging.DEBUG if conf.get('DEBUG', False) else logging.INFO)

try:
global arc
Expand Down
57 changes: 43 additions & 14 deletions doc/source/sysadmin.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
Sysadmin
=========

.. highlight:: bash

Installation
-------------

We only maintain packages for debian stretch. They work fine in debian jessie,
too. Still, installing libreant is easy on most distributions.

System dependencies
^^^^^^^^^^^^^^^^^^^^
.. note::
In this moment we do *not* support elasticsearch v2.
There are plans to do it shortly!

Debian wheezy / Debian jessie / Ubuntu
Debian jessie / Debian stretch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. highlight:: bash

Download and install the Public Signing Key for elasticsearch repo::
You need to add two custom repositories: one for elasticsearch, the other for
libreant itself::

wget -qO - 'http://packages.elasticsearch.org/GPG-KEY-elasticsearch' | sudo apt-key add -
wget -qO - 'http://deb.libreant.ga/repokey.gpg' | sudo apt-key add -
echo 'deb http://packages.elasticsearch.org/elasticsearch/1.7/debian stable main' | sudo tee '/etc/apt/sources.list.d/elasticsearch.list'
echo 'deb http://deb.libreant.ga/libreant-debian/ testing/' | sudo tee '/etc/apt/sources.list.d/libreant.list'

wget -qO - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add -

Add elasticsearch repos in /etc/apt/sources.list.d/elasticsearch.list::
If you are using debian jessie, you need to add stretch repositories::

echo "deb http://packages.elasticsearch.org/elasticsearch/1.7/debian stable main" | sudo tee /etc/apt/sources.list.d/elasticsearch.list
echo "deb http://ftp.debian.org/debian stretch main" | sudo tee /etc/apt/sources.list.d/stretch.list

Install requirements::
Install everything::

sudo apt-get update && sudo apt-get install python2.7 gcc python2.7-dev python-virtualenv openjdk-7-jre-headless elasticsearch
sudo apt-get update && sudo apt-get install openjdk-7-jre-headless elasticsearch python-libreant

.. note::

Expand All @@ -35,20 +47,28 @@ Arch

Install all necessary packages::

sudo pacman -Sy python2 python2-virtualenv elasticsearch
sudo pacman -Sy python2 python2-virtualenv

And take care to install elasticsearch<2.x::

wget https://archive.archlinux.org/packages/e/elasticsearch/elasticsearch-1.7.3-1-x86_64.pkg.tar.xz
wget https://archive.archlinux.org/packages/e/elasticsearch/elasticsearch-1.7.3-1-x86_64.pkg.tar.xz.sig
sudo pacman-key --verify elasticsearch-1.7.3-1-x86_64.pkg.tar.xz elasticsearch-1.7.3-1-x86_64.pkg.tar.xz.sig
sudo pacman -U elasticsearch-1.7.3.1-x86_64.pkg.tar.xz
echo "IgnorePkg elasticsearch" | sudo tee -a /etc/pacman.conf

Python dependencies
^^^^^^^^^^^^^^^^^^^^

Create a virtual env::
Clone libreant repository and create a virtual env::

virtualenv -p /usr/bin/python2 ve

Install libreant and all python dependencies::

./ve/bin/pip install libreant

Execution
Running
----------

Start elsticsearch
Expand All @@ -67,8 +87,8 @@ Start elasticsearch service::

sudo update-rc.d elasticsearch defaults 95 10

Arch / Debian jessie
~~~~~~~~~~~~~~~~~~~~
Arch / Debian jessie / Debian stretch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Start elasticsearch service::

Expand All @@ -79,11 +99,20 @@ Start elasticsearch service::
If you want to automatically start elasticsearch during bootup::

sudo systemctl enable elasticsearch

These instructions apply both to arch and debian, but should not be needed
on debian: after the installation, elasticsearch is enabled and started
automatically.


Start libreant
^^^^^^^^^^^^^^
To execute libreant::

On debian stretch, the systemd unit ``libreant.service`` will take care
of starting libreant. You will find it automatically started and enabled after
the installation, so you have nothing to do.

On debian wheezy and archlinux, this is what you need to run::

./ve/bin/libreant

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def read(fname):
'cli',
'conf'],
install_requires=[
'gevent',
'gevent >=1.0.1, <=1.1', # gevent version 1.0.0 do not support pyhton 2.7.8 https://github.com/gevent/gevent/issues/513
'elasticsearch >=1, <2',
'flask-bootstrap',
'Flask-Babel',
Expand Down
4 changes: 2 additions & 2 deletions utils/loggers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging


LOG_NAMES = ['webant', 'fsdb', 'presets', 'agherant', 'config_utils', 'libreantdb', 'archivant', 'users']
LOG_NAMES = ['webant', 'fsdb', 'presets', 'agherant', 'config_utils', 'libreantdb', 'archivant', 'users', 'werkzeug']


def initLoggers(logLevel=logging.WARNING, logNames=LOG_NAMES):
def initLoggers(logLevel=logging.INFO, logNames=LOG_NAMES):
streamHandler = logging.StreamHandler()
formatter = logging.Formatter(
'%(asctime)s [%(name)s] [%(levelname)s] %(message)s')
Expand Down
32 changes: 20 additions & 12 deletions webant/api/users_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def delete_user(userID):
@route('/users/', methods=['POST'])
def add_user():
request.on_json_loading_failed = on_json_load_error
userData = request.json
userData = request.get_json()
# the next two lines should be removed when Flask version is >= 1.0
if not userData:
raise ApiError("Unsupported media type", 415)
name = userData.get('name', None)
Expand All @@ -52,10 +53,12 @@ def add_user():
@route('/users/<int:userID>', methods=['PATCH'])
def update_user(userID):
request.on_json_loading_failed = on_json_load_error
if not request.json:
userData = request.get_json()
# the next two lines should be removed when Flask version is >= 1.0
if not userData:
raise ApiError("Unsupported media type", 415)
try:
users.api.update_user(userID, request.json)
users.api.update_user(userID, userData)
except users.api.NotFoundException, e:
raise ApiError("Not found", 404, details=str(e))
return make_success_response("user has been successfully updated")
Expand All @@ -82,7 +85,8 @@ def delete_group(groupID):
@route('/groups/', methods=['POST'])
def add_group():
request.on_json_loading_failed = on_json_load_error
groupData = request.json
groupData = request.get_json()
# the next two lines should be removed when Flask version is >= 1.0
if not groupData:
raise ApiError("Unsupported media type", 415)
name = groupData.get('name', None)
Expand All @@ -102,10 +106,12 @@ def add_group():
@route('/groups/<int:groupID>', methods=['PATCH'])
def update_group(groupID):
request.on_json_loading_failed = on_json_load_error
if not request.json:
groupData = request.get_json()
# the next two lines should be removed when Flask version is >= 1.0
if not groupData:
raise ApiError("Unsupported media type", 415)
try:
users.api.update_group(groupID, request.json)
users.api.update_group(groupID, groupData)
except users.api.NotFoundException, e:
raise ApiError("Not found", 404, details=str(e))
return make_success_response("group has been successfully updated")
Expand Down Expand Up @@ -171,7 +177,8 @@ def delete_capability(capID):
@route('/capabilities/', methods=['POST'])
def add_capability():
request.on_json_loading_failed = on_json_load_error
capData = request.json
capData = request.get_json()
# the next two lines should be removed when Flask version is >= 1.0
if not capData:
raise ApiError("Unsupported media type", 415)
domain = capData.get('domain', None)
Expand All @@ -194,13 +201,14 @@ def add_capability():
@route('/capabilities/<int:capID>', methods=['PATCH'])
def update_capability(capID):
request.on_json_loading_failed = on_json_load_error
if not request.json:
capData = request.get_json()
# the next two lines should be removed when Flask version is >= 1.0
if not capData:
raise ApiError("Unsupported media type", 415)
updates = request.json
if 'actions' in updates:
updates['action'] = Action.from_list(updates.pop('actions'))
if 'actions' in capData:
capData['action'] = Action.from_list(capData.pop('actions'))
try:
users.api.update_capability(capID, updates)
users.api.update_capability(capID, capData)
except users.api.NotFoundException, e:
raise ApiError("Not found", 404, details=str(e))
return make_success_response("capability has been successfully updated")
Expand Down
4 changes: 3 additions & 1 deletion webant/api/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import jsonify
from flask import jsonify, request


class ApiError(Exception):
Expand All @@ -14,6 +14,8 @@ def __str__(self):


def on_json_load_error(e):
if request.mimetype != 'application/json':
raise ApiError("Wrong media type", 415, details="Expected 'application/json' encoded data" )
raise ApiError("Bad request", 400, details=str(e))


Expand Down
13 changes: 10 additions & 3 deletions webant/webserver_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ def gevent_run(app):
run_app = DebuggedApplication(app)

def run_server():
from gevent import version_info

logger = app._logger
port = int(app.config.get('PORT', 5000))
address = app.config.get('ADDRESS', '')
print('Listening on http://%s:%d/' % (address or '0.0.0.0', port))
http_server = WSGIServer((address, port), run_app)
logger.info('Listening on http://{}:{}/'.format(address or '0.0.0.0', port))
server_params = dict()
#starting from gevent version 1.1b1 we can pass custom logger to gevent
if version_info[:2] >= (1,1):
server_params['log'] = logger
http_server = WSGIServer((address, port), run_app, **server_params)
http_server.serve_forever()

if app.config['DEBUG']:
from werkzeug.serving import run_with_reloader
from werkzeug._reloader import run_with_reloader
run_with_reloader(run_server)
else:
run_server()