Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit

  • Loading branch information...
commit 22cc5f5744b32c5a0e22a703e309342952fd2a8c 1 parent 50f7d40
Lars Holm Nielsen authored
1  AUTHORS
... ... @@ -0,0 +1 @@
  1 +Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
14 LICENSE
... ... @@ -0,0 +1,14 @@
  1 +Copyright (C) 2012 CERN.
  2 +
  3 +This program is free software; you can redistribute it and/or modify
  4 +it under the terms of the GNU General Public License as published by
  5 +the Free Software Foundation; either version 2 of the License, or
  6 +(at your option) any later version.
  7 +
  8 +This program is distributed in the hope that it will be useful, but
  9 +WITHOUT ANY WARRANTY; without even the implied warranty of
  10 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11 +General Public License for more details.
  12 +
  13 +You should have received a copy of the GNU General Public License
  14 +along with this program; if not, see <http://www.gnu.org/licenses/>.
23 MANIFEST.in
... ... @@ -0,0 +1,23 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +#
  23 +include README.md AUTHORS LICENSE
21 README.md
Source Rendered
... ... @@ -1,4 +1,21 @@
1   -invenio-fabric
  1 +Invenio Fabric
2 2 ==============
  3 +Fabric tasks for bootstrapping, installing, deploying and running Invenio on CERN Scientific
  4 +Linux 5/6 hosts.
3 5
4   -Fabric tasks for bootstrapping, installing, deploying and running Invenio at CERN on Scientific Linux 5/6 hosts.
  6 +The tasks follows the guidelines on installing Invenio on SLC5/6 - see more on:
  7 +
  8 + * http://invenio-software.org/wiki/Installation/InvenioOnSLC5
  9 +
  10 +Requirements:
  11 +
  12 + * User must have sudo rights to remote machine.
  13 + * Configuration files must be stored locally (see path for each env definiton)
  14 + * Fabric 1.4+
  15 +
  16 +Example usage::
  17 +
  18 + fab -u <user> openaire_dev bootstrap
  19 + fab -u <user> openaire_dev install
  20 + fab -u <user> openaire_dev deploy
  21 + fab -u <user> openaire_dev invenio_updateconf
41 setup.py
... ... @@ -0,0 +1,41 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +
  24 +from setuptools import setup, find_packages
  25 +
  26 +setup(
  27 + name = 'invenio-fabric',
  28 + version = '0.1',
  29 + packages = find_packages('src'),
  30 + package_dir = { '': 'src' },
  31 + include_package_data = False,
  32 + zip_safe = False,
  33 + install_requires = [ 'distribute', 'Fabric>=1.4', ],
  34 +
  35 + author = 'Lars Holm Nielsen',
  36 + author_email = 'lars.holm.nielsen@cern.ch',
  37 + description = 'Fabric tasks for installing, deploying and running Invenio on CERN SLC5/6 hosts.',
  38 + license = "GPL",
  39 + keywords = "invenio fabric cern",
  40 + url = "https://github.com/lnielsen-cern/invenio-fabric"
  41 +)
42 src/inveniofab/__init__.py
... ... @@ -0,0 +1,42 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +"""
  24 +Fabric tasks for bootstrapping, installing, deploying and running Invenio at
  25 +CERN on Scientific Linux 5/6 hosts.
  26 +
  27 +The tasks follows the guidelines on installing Invenio on SLC5/6 - see more on:
  28 +
  29 + * http://invenio-software.org/wiki/Installation/InvenioOnSLC5
  30 +
  31 +Example usage:
  32 +
  33 + fab -u <user> openaire_dev bootstrap
  34 + fab -u <user> openaire_dev install
  35 + fab -u <user> openaire_dev deploy
  36 + fab -u <user> openaire_dev invenio_updateconf
  37 +
  38 +Requirements:
  39 + * User must have sudo rights to remote machine.
  40 + * Configuration files must be stored locally (see path for each env definiton)
  41 + * Fabric 1.4+
  42 +"""
76 src/inveniofab/apache.py
... ... @@ -0,0 +1,76 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +
  24 +"""
  25 +Library tasks for Apache library tasks
  26 +"""
  27 +
  28 +from fabric.api import roles, sudo, task
  29 +from fabric.contrib.files import append, comment, uncomment, sed
  30 +
  31 +HTTPD_CONF_EXTRAS = [
  32 +"Include /opt/invenio/etc/apache/invenio-apache-vhost.conf",
  33 +"Include /opt/invenio/etc/apache/invenio-apache-vhost-ssl.conf",
  34 +"TraceEnable off",
  35 +"SSLProtocol all -SSLv2",
  36 +]
  37 +
  38 +@roles('web')
  39 +@task
  40 +def apache_prepare():
  41 + """
  42 + Prepare Apache on SLC5/6 host
  43 + """
  44 + sudo("/sbin/service httpd start")
  45 + sudo("/sbin/chkconfig httpd on")
  46 +
  47 +
  48 +@roles('web')
  49 +@task
  50 +def apache_configure():
  51 + """
  52 + Configure Apache on SLC5/6 host
  53 + """
  54 + apache_conf = "/etc/httpd/conf/httpd.conf"
  55 + append(apache_conf, HTTPD_CONF_EXTRAS, use_sudo = True)
  56 + comment(apache_conf, '^Alias /error/ .+', use_sudo = True)
  57 +
  58 +
  59 +@roles('web')
  60 +@task
  61 +def apache_clean():
  62 + """
  63 + Remove all configuration directives added to httpd.conf.
  64 + """
  65 + for line in HTTPD_CONF_EXTRAS:
  66 + sed("/etc/httpd/conf/httpd.conf", line, "", use_sudo = True)
  67 + uncomment("/etc/httpd/conf/httpd.conf", 'Alias \/error\/ .+', use_sudo = True)
  68 +
  69 +
  70 +@roles('web')
  71 +@task
  72 +def apache_restart():
  73 + """
  74 + Restart Apache
  75 + """
  76 + sudo("/sbin/service httpd restart")
42 src/inveniofab/api.py
... ... @@ -0,0 +1,42 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +"""
  24 +Definition of Invenio Fabric API. To make all the library tasks available
  25 +in a fabfile.py you just have to have the following import in the top
  26 +of your file::
  27 +
  28 + from inveniofab.api import *
  29 +"""
  30 +
  31 +from inveniofab.apache import apache_clean, apache_configure, apache_prepare, \
  32 + apache_restart
  33 +from inveniofab.bibsched import bibsched_halt, bibsched_schedule, bibsched_start, \
  34 + bibsched_status, bibsched_stop
  35 +from inveniofab.env import bootstrap, clean, deploy, install
  36 +from inveniofab.invenio import invenio_clean, invenio_configure, invenio_deploy, \
  37 + invenio_install, invenio_updateconf
  38 +from inveniofab.mysql import mysql_prepare, mysql_loaddump, mysql_dropdb, \
  39 + mysql_createdb
  40 +from inveniofab.python import python_clean, python_prepare
  41 +from inveniofab.system import crontab_install, crontab_show, crontab_uninstall, \
  42 + libreoffice_prepare, selinux_prepare
78 src/inveniofab/bibsched.py
... ... @@ -0,0 +1,78 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +"""
  24 +Library tasks for configuring and running bibsched.
  25 +"""
  26 +
  27 +from fabric.api import sudo, env, roles, task
  28 +from inveniofab.env import env_settings
  29 +
  30 +@roles('backend')
  31 +@task
  32 +def bibsched_start():
  33 + """
  34 + Start bibsched
  35 + """
  36 + sudo("/opt/invenio/bin/bibsched start", user="apache")
  37 +
  38 +
  39 +@roles('backend')
  40 +@task
  41 +def bibsched_stop():
  42 + """
  43 + Stop bibsched
  44 + """
  45 + sudo("/opt/invenio/bin/bibsched stop", user="apache")
  46 +
  47 +
  48 +@roles('backend')
  49 +@task
  50 +def bibsched_halt():
  51 + """
  52 + Halt bibsched
  53 + """
  54 + sudo("/opt/invenio/bin/bibsched halt", user="apache")
  55 +
  56 +
  57 +@roles('backend')
  58 +@task
  59 +def bibsched_status():
  60 + """
  61 + Bibsched status
  62 + """
  63 + sudo("/opt/invenio/bin/bibsched status", user="apache")
  64 +
  65 +
  66 +@roles('backend')
  67 +@task
  68 +def bibsched_schedule():
  69 + """
  70 + Schedule bibsched tasks to run
  71 + """
  72 + try:
  73 + tasks = env_settings('bibsched')['schedule']
  74 + except KeyError:
  75 + tasks = []
  76 +
  77 + for t in tasks:
  78 + sudo("/opt/invenio/bin/%s" % t, user="apache")
184 src/inveniofab/env.py
... ... @@ -0,0 +1,184 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +"""
  24 +Configurable compound tasks for bootstrapping, installing, configuring,
  25 +deploying and running Invenio.
  26 +"""
  27 +
  28 +from fabric.api import env, execute, abort, task
  29 +
  30 +# ==============
  31 +# Compound tasks
  32 +# ==============
  33 +@task
  34 +def install():
  35 + """
  36 + Install Invenio and configure installation from scratch
  37 + """
  38 + _run_task_group('install')
  39 +
  40 +@task
  41 +def clean():
  42 + """
  43 + Clean existing Invenio installation
  44 + """
  45 + _run_task_group('clean')
  46 +
  47 +@task
  48 +def deploy():
  49 + """
  50 + Deploy Invenio from latest master
  51 + """
  52 + _run_task_group('deploy')
  53 +
  54 +@task
  55 +def bootstrap():
  56 + """
  57 + Bootstrap host system(s)
  58 + """
  59 + _run_task_group('bootstrap')
  60 +
  61 +
  62 +def _run_task_group(arg):
  63 + """
  64 + Helper function to run a task group
  65 + """
  66 + try:
  67 + import inveniofab.api
  68 +
  69 + for task in env_settings('tasks')[arg]:
  70 + if not callable(task):
  71 + task = getattr(inveniofab.api, task)
  72 + execute(task)
  73 + except AttributeError:
  74 + abort("No %s tasks defined." % arg)
  75 +
  76 +# =======================
  77 +# Default Fabric settings
  78 +# =======================
  79 +def env_init(name):
  80 + """
  81 + Initialize default environment
  82 +
  83 + ENV_SETTINGS is a dictionary of settings that is initialized by
  84 + an environment. The settings are used to configure the tasks
  85 + for each specific environment (e.g. which conf file to use,
  86 + database name, bibsched tasks etc). Following is a short reference
  87 + of settings:
  88 +
  89 + * localconf: Local path to an invenio-local.conf for env.
  90 + * crontab: Local path to a crontab file for env.
  91 + * schedule: A list of string commands used to set the
  92 + * db:
  93 + * dbdump_dir:
  94 + """
  95 + if not hasattr(env, 'ENVIRONMENTS'):
  96 + env.ENVIRONMENTS = {
  97 + 'defs' : {},
  98 + 'default' : None,
  99 + 'active' : None,
  100 + }
  101 +
  102 + if name not in env.ENVIRONMENTS:
  103 + env_setdefault(name)
  104 + env.ENVIRONMENTS['defs'][name] = {
  105 + 'roledefs' : {
  106 + 'web' : [],
  107 + 'db' : [],
  108 + 'backend' : [],
  109 + },
  110 + 'settings' : {
  111 + 'tasks' : {
  112 + 'bootstrap' : ['python_prepare', 'selinux_prepare', 'mysql_prepare', 'mysql_createdb', 'apache_prepare', 'apache_configure'],
  113 + 'install' : ['invenio_install', 'invenio_configure', 'libreoffice_prepare', 'apache_restart'],
  114 + 'deploy' : ['invenio_deploy', 'apache_restart'],
  115 + 'clean' : ['python_clean', 'apache_clean', 'apache_restart', 'mysql_dropdb', 'invenio_clean',],
  116 + },
  117 + 'bibsched' : {
  118 + 'schedule' : [
  119 + "bibindex -f50000 -s5m -u admin",
  120 + "bibrank -f50000 -s5m -u admin",
  121 + "bibreformat -oHB -s5m -u admin",
  122 + "webcoll -v0 -s5m -u admin",
  123 + "bibsort -s5m -u admin",
  124 + "bibrank -f50000 -R -wwrd -s14d -LSunday -u admin",
  125 + "bibsort -R -s7d -L 'Sunday 01:00-05:00' -u admin",
  126 + "inveniogc -a -s7d -L 'Sunday 01:00-05:00' -u admin",
  127 + "batchuploader --documents -s20m -u admin",
  128 + "batchuploader --metadata -s20m -u admin",
  129 + "dbdump -s 20h -L '22:00-06:00' -n 10 -u admin",
  130 + "oairepositoryupdater -s1h -u admin",
  131 + "oaiharvest -s 24h -u admin",
  132 + ]
  133 + },
  134 + 'invenio' : {
  135 + 'conffile' : [],
  136 + },
  137 + 'mysql' : {
  138 + 'db' : { 'name' : 'invenio', },
  139 + 'dbdump_dir' : None,
  140 + },
  141 + 'system' : {
  142 + 'crontab' : None,
  143 + },
  144 + },
  145 + }
  146 + env_setdefault(name)
  147 + return (env.ENVIRONMENTS['defs'][name]['roledefs'], env.ENVIRONMENTS['defs'][name]['settings'])
  148 +
  149 +
  150 +def env_setdefault(name):
  151 + """
  152 + Set an initialized environment as default (used when editing the settings)
  153 + """
  154 + if not hasattr(env, 'ENVIRONMENTS'):
  155 + abort("You must first initialize an environment before calling env_setdefault.")
  156 + env.ENVIRONMENTS['default'] = name
  157 +
  158 +
  159 +def env_default():
  160 + """
  161 + Get the current default environment (used when editing the settings).
  162 + """
  163 + try:
  164 + return env.ENVIRONMENTS['defs'][env.ENVIRONMENTS['default']]
  165 + except AttributeError:
  166 + abort("You must first initialize an environment before calling env_getdefault.")
  167 + except KeyError:
  168 + abort("No default environment set.")
  169 +
  170 +
  171 +def env_activate(name):
  172 + """
  173 + Activate an environment (so env_settings will return values from this env).
  174 + """
  175 + env.roledefs = env.ENVIRONMENTS['defs'][name]['roledefs']
  176 + env.ENV_SETTINGS = env.ENVIRONMENTS['defs'][name]['settings']
  177 +
  178 +
  179 +def env_settings(module, envname = None):
  180 + """
  181 + Get settings for a particular module.
  182 + """
  183 + return env.ENV_SETTINGS[module] if not envname else env.ENVIRONMENTS['defs'][envname]['settings'][module]
  184 +
120 src/inveniofab/invenio.py
... ... @@ -0,0 +1,120 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +from fabric.api import roles, cd, run, sudo, abort, env, put, task
  24 +from fabric.contrib.files import comment, sed, exists
  25 +from inveniofab.env import env_settings
  26 +from inveniofab.utils import slc_version
  27 +import os
  28 +
  29 +# ============================
  30 +# Invenio library tasks (SLC5)
  31 +# ============================
  32 +@roles('web')
  33 +@task
  34 +def invenio_install():
  35 + """
  36 + Install Invenio.
  37 + """
  38 + if not exists("/tmp/invenio"):
  39 + with cd("/tmp"):
  40 + run("git clone http://invenio-software.org/repo/invenio")
  41 +
  42 + with cd("/tmp/invenio"):
  43 + run("aclocal && automake -a && autoconf")
  44 + run("./configure && make")
  45 + sudo("make install", user = "apache")
  46 + sudo("make install-mathjax-plugin", user = "apache")
  47 + sudo("make install-ckeditor-plugin", user = "apache")
  48 + sudo("make install-pdfa-helper-files", user = "apache")
  49 + sudo("make install-jquery-plugins", user = "apache")
  50 +
  51 +
  52 +@roles('web')
  53 +@task
  54 +def invenio_deploy():
  55 + """
  56 + Deploy latest Invenio master branch
  57 + """
  58 + with cd("/tmp/invenio"):
  59 + run("git pull")
  60 + run("make -s")
  61 + sudo("make install", user = "apache")
  62 + sudo("/opt/invenio/bin/inveniocfg --update-all", user = "apache")
  63 +
  64 +
  65 +@roles('web')
  66 +@task
  67 +def invenio_clean():
  68 + """
  69 + Clean Invenio installation
  70 + """
  71 + with cd("/tmp"):
  72 + sudo("rm -Rf /tmp/invenio")
  73 + sudo("rm -Rf /opt/invenio")
  74 +
  75 +
  76 +@roles('web')
  77 +@task
  78 +def invenio_configure(host = None):
  79 + """
  80 + Configure Invenio
  81 + """
  82 + invenio_updateconf(host = host)
  83 + sudo("/opt/invenio/bin/inveniocfg --create-tables", user = "apache")
  84 + sudo("/opt/invenio/bin/inveniocfg --create-apache-conf", user = "apache")
  85 +
  86 + slcver = slc_version()
  87 + if slcver and slcver[0] < 6:
  88 + comment("/opt/invenio/etc/apache/invenio-apache-vhost.conf", 'WSGIImportScript', use_sudo = True)
  89 + comment("/opt/invenio/etc/apache/invenio-apache-vhost-ssl.conf", 'WSGIImportScript', use_sudo = True)
  90 +
  91 +
  92 +@roles('web')
  93 +@task
  94 +def invenio_updateconf(host = None):
  95 + """
  96 + Update Invenio configuration
  97 + """
  98 + conffile = env_settings('invenio')['conffile'] or os.path.join(os.getcwd(), 'invenio-local.conf')
  99 + remote_conffile = "/opt/invenio/etc/invenio-local.conf"
  100 + if not os.path.exists(conffile):
  101 + abort("Configuration file %s does not exists." % conffile)
  102 + put(conffile, remote_conffile, use_sudo = True)
  103 + sudo("chown apache:apache %s" % remote_conffile)
  104 + sudo("chmod 644 %s" % remote_conffile)
  105 +
  106 + # Adapt configuration file if needed
  107 + if host:
  108 + _edit_simple_cfg_option(remote_conffile, 'CFG_SITE_URL', 'http://%s' % host, use_sudo = True)
  109 + _edit_simple_cfg_option(remote_conffile, 'CFG_SITE_SECURE_URL', 'https://%s' % host, use_sudo = True)
  110 +
  111 + sudo("/opt/invenio/bin/inveniocfg --update-all", user = "apache")
  112 +
  113 +
  114 +def _edit_simple_cfg_option( filename, opt, value, **kwargs ):
  115 + """
  116 + Edit an configuration variable in invenio-local.conf, replace the existing value with
  117 + the provided one.
  118 + """
  119 + sed(filename, "^(%s\s*=).+$" % opt, "\\1 = %s" % value, **kwargs)
  120 +
108 src/inveniofab/mysql.py
... ... @@ -0,0 +1,108 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +"""
  24 +Library tasks for configuring and running MySQL for Invenio.
  25 +"""
  26 +
  27 +from fabric.api import roles, sudo, env, prompt, run, abort, task
  28 +from fabric.contrib.console import confirm
  29 +from fabric.contrib.files import exists
  30 +from inveniofab.env import env_settings
  31 +from inveniofab.utils import slc_version
  32 +
  33 +@roles('db')
  34 +@task
  35 +def mysql_prepare():
  36 + """
  37 + Prepare MySQL on SLC5 host
  38 + """
  39 + sudo("/sbin/service mysqld start")
  40 + sudo("/sbin/chkconfig mysqld on")
  41 +
  42 + if confirm("Secure MySQL installation?"):
  43 + sudo("/usr/bin/mysql_secure_installation")
  44 +
  45 + # Create DB dump dir
  46 + dumpdir = env_settings('mysql')['dbdump_dir'] or '/opt/invenio/var/log'
  47 + if dumpdir:
  48 + sudo("mkdir -p %s" % dumpdir, user="apache")
  49 + sudo("chown apache:apache %s" % dumpdir, user="apache")
  50 + sudo("chmod 755 %s" % dumpdir, user="apache")
  51 +
  52 +
  53 +@roles('db')
  54 +@task
  55 +def mysql_createdb():
  56 + """
  57 + Create database and user for Invenio
  58 + """
  59 + # Create context
  60 + ctx = env_settings('mysql')['db']
  61 + if 'user' not in ctx:
  62 + ctx['user'] = ctx['name']
  63 + if 'password' not in ctx:
  64 + newpw = prompt('Enter new MySQL Invenio user password (typing will be visible, default is my123p$ss):')
  65 + ctx['password'] = "my123p$ss" if not newpw else newpw
  66 +
  67 + # Escape quote characters
  68 + ctx['password'] = ctx['password'].replace('"', '\"')
  69 + ctx['password'] = ctx['password'].replace("'", "\'")
  70 +
  71 + # Run commands
  72 + run('mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS %(name)s DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"' % ctx)
  73 + run('mysql -u root -p -e "GRANT ALL PRIVILEGES ON %(name)s.* TO %(user)s@localhost IDENTIFIED BY \'%(password)s\';"' % ctx)
  74 + run('mysqladmin -u root -p flush-privileges')
  75 +
  76 +
  77 +@roles('db')
  78 +@task
  79 +def mysql_dropdb():
  80 + """
  81 + Create database and user for Invenio
  82 + """
  83 + # Create context
  84 + ctx = env_settings('mysql')['db']
  85 + if 'user' not in ctx:
  86 + ctx['user'] = ctx['name']
  87 +
  88 + # Run commands
  89 + run('mysql -u root -p -e "DROP DATABASE IF EXISTS %(name)s"' % ctx)
  90 + run('mysql -u root -p -e "REVOKE ALL PRIVILEGES ON %(name)s.* FROM %(user)s@localhost"' % ctx)
  91 + run('mysqladmin -u root -p flush-privileges')
  92 +
  93 +
  94 +@roles('db')
  95 +@task
  96 +def mysql_loaddump( dumpfile ):
  97 + """
  98 + Load MySQL dump file
  99 + """
  100 + if not exists(dumpfile, use_sudo = True):
  101 + abort("File %s does not exists." % dumpfile)
  102 +
  103 + if confirm("This will erease all data in the existing database. Are you sure you want to load %s?" % dumpfile):
  104 + ctx = env_settings('mysql')['db']
  105 + ctx['dumpfile'] = dumpfile
  106 + run('mysql -u root -p -e "DROP DATABASE IF EXISTS %(name)s"' % ctx)
  107 + run('mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS %(name)s DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"' % ctx)
  108 + run('mysql -u root -f -p %(name)s < %(dumpfile)s' % ctx)
57 src/inveniofab/python.py
... ... @@ -0,0 +1,57 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +"""
  24 +Library tasks for setting up Python for Invenio on SLC5/6 host.
  25 +"""
  26 +
  27 +from fabric.api import roles, run, sudo, task
  28 +from fabric.contrib.files import exists
  29 +
  30 +@roles('web')
  31 +@task
  32 +def python_prepare():
  33 + """
  34 + Setup Python symlinks
  35 + """
  36 + pyver = run("python -c \"import sys;print '%s.%s' % sys.version_info[:2]\"")
  37 +
  38 + sudo("chgrp apache /opt")
  39 + sudo("chmod g+w /opt")
  40 + sudo("mkdir -p /opt/invenio/lib/python/invenio")
  41 + sudo("chown -R apache /opt/invenio/")
  42 + if not exists('/usr/lib64/python%s/site-packages/invenio' % pyver):
  43 + sudo("ln -s /opt/invenio/lib/python/invenio /usr/lib64/python%s/site-packages/invenio" % pyver )
  44 + if not exists('/usr/lib/python%s/site-packages/invenio' % pyver):
  45 + sudo("ln -s /opt/invenio/lib/python/invenio /usr/lib/python%s/site-packages/invenio" % pyver)
  46 +
  47 +
  48 +@roles('web')
  49 +@task
  50 +def python_clean():
  51 + """
  52 + Setup Python symlinks
  53 + """
  54 + if exists('/usr/lib64/python2.4/site-packages/invenio'):
  55 + sudo("rm -f /usr/lib64/python2.4/site-packages/invenio")
  56 + if exists('/usr/lib/python2.4/site-packages/invenio'):
  57 + sudo("rm -f /usr/lib/python2.4/site-packages/invenio")
106 src/inveniofab/system.py
... ... @@ -0,0 +1,106 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +from fabric.api import roles, sudo, env, abort, put, settings, task
  24 +from fabric.contrib.files import contains, sed
  25 +from inveniofab.env import env_settings
  26 +from inveniofab.utils import slc_version
  27 +import os
  28 +
  29 +"""
  30 +Library tasks for configuring SLC5/6 system (crontabs, SELinux, OpenOffice).
  31 +"""
  32 +
  33 +# ============================
  34 +# SELinux library tasks (SLC5)
  35 +# ============================
  36 +@roles('web')
  37 +@task
  38 +def selinux_prepare():
  39 + """
  40 + Setup SELinux on host
  41 + """
  42 + slcver = slc_version()
  43 + if slcver and slcver[0] < 6:
  44 + sudo("/usr/sbin/setenforce Permissive")
  45 + sudo("sed -e 's/^SELINUX=enforcing$/SELINUX=permissive/g' < /etc/selinux/config > ~/selinux_config.new")
  46 + sudo("cp ~/selinux_config.new /etc/selinux/config && rm ~/selinux_config.new")
  47 +
  48 +
  49 +# =========================
  50 +# LibreOffice library tasks
  51 +# =========================
  52 +@roles('web')
  53 +@task
  54 +def libreoffice_prepare():
  55 + """
  56 + Setup LibreOffice on host
  57 + """
  58 + # Note, editing /etc/sudoers should be moved to Quattor
  59 + slcver = slc_version()
  60 + if slcver and slcver[0] < 6:
  61 + if not contains("/etc/sudoers", "NOPASSWD: /opt/invenio/bin/inveniounoconv", use_sudo = True):
  62 + sed("/etc/sudoers", "^(apache\s+ALL=.+)$", "\\1, (nobody) NOPASSWD: /opt/invenio/bin/inveniounoconv", use_sudo = True)
  63 + sudo("mkdir -p /opt/invenio/var/tmp/ooffice-tmp-files")
  64 + sudo("chown -R nobody /opt/invenio/var/tmp/ooffice-tmp-files")
  65 + sudo("chmod -R 755 /opt/invenio/var/tmp/ooffice-tmp-files")
  66 + sudo("/opt/invenio/bin/inveniocfg --check-openoffice", user = "apache")
  67 +
  68 +# =====================
  69 +# Crontab library tasks
  70 +# =====================
  71 +@roles('backend')
  72 +@task
  73 +def crontab_install():
  74 + """
  75 + Install crontab on backend server
  76 + """
  77 + crontab = env_settings('system')['crontab']
  78 + if not crontab:
  79 + abort("No crontab defined for environment.")
  80 + if not os.path.exists(crontab):
  81 + abort("Crontab file %s does not exists." % crontab)
  82 + remote = "/opt/invenio/etc/crontab"
  83 + put(crontab, remote, use_sudo = True)
  84 + sudo("chown apache:apache %s" % remote)
  85 + sudo("chmod 644 %s" % remote)
  86 + sudo("crontab %s" % remote, user = "apache")
  87 +
  88 +
  89 +@roles('backend')
  90 +@task
  91 +def crontab_uninstall():
  92 + """
  93 + Uninstall crontab on backend server
  94 + """
  95 + with settings( warn_only=True ):
  96 + sudo("crontab -r", user = "apache")
  97 +
  98 +
  99 +@roles('backend')
  100 +@task
  101 +def crontab_show():
  102 + """
  103 + Show installed crontab on backend server
  104 + """
  105 + with settings( warn_only=True ):
  106 + sudo("crontab -l", user = "apache")
43 src/inveniofab/utils.py
... ... @@ -0,0 +1,43 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# A Fabric file for installing, deploying and running Invenio on CERN
  4 +# SLC5/6 hosts.
  5 +#
  6 +# Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  7 +#
  8 +# Copyright (C) 2012 CERN.
  9 +#
  10 +# This program is free software; you can redistribute it and/or modify
  11 +# it under the terms of the GNU General Public License as published by
  12 +# the Free Software Foundation; either version 2 of the License, or
  13 +# (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful, but
  16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18 +# General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, see <http://www.gnu.org/licenses/>.
  22 +
  23 +"""
  24 +Utility and helper functions. Functions in this module are not
  25 +meant as standalone Fabric tasks, but for usage in other library
  26 +tasks.
  27 +"""
  28 +
  29 +from fabric.api import env, run
  30 +import re
  31 +
  32 +def slc_version():
  33 + """
  34 + Determine Scientific Linux CERN version
  35 + """
  36 + if not hasattr(env, 'SLC_VERSION'):
  37 + osver = run("cat /etc/redhat-release")
  38 + m = re.match("Scientific Linux CERN SLC release ([0-9])\.([0-9]) \([A-Za-z-_ ]+\)", osver)
  39 + if m:
  40 + env.SLC_VERSION = (int(m.group(1)), int(m.group(2)))
  41 + else:
  42 + env.SLC_VERSION = (int(m.group(1)), int(m.group(2)))
  43 + return env.SLC_VERSION

0 comments on commit 22cc5f5

Please sign in to comment.
Something went wrong with that request. Please try again.