Commit 9e4c1472 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'rpm' into 'devel_11.1.x'

added RPM packaging

See merge request piotr.gawron/minerva!124
parents 1e7c7fb8 5b38682d
......@@ -9,6 +9,8 @@ versionCompLt() {
[ "$1" = "$2" ] && return 1 || versionCompLte $1 $2
}
# file with bash code generating DB schema diffs for different versions
dbschemadiff=management_scripts/db_schema_and_diff.sh
#Where source file of the debian package should be placed
SRC_DIR=debian/src
......@@ -54,22 +56,9 @@ cp debian/scripts/common.sh $SRC_DIR/
#copy changelog file
cp CHANGELOG $ROOT_DIR/debian/template/changelog
#this variable will contain all available versions of the package
versions=();
#this is current (latest) version of the package
current_version=-1;
#find all available versions
for version in `ls $DB_SCHEMA_DIR | sort -V`;
do
if [ -d "$DB_SCHEMA_DIR/$version" ]
then
versions+=($version);
current_version=$version;
fi
done
# set $versions and $current_version; generate upgrade scripts in SRC_DIR
DBSCRIPT_DEST_DIR=$SRC_DIR
source $dbschemadiff
echo "Current version: " $current_version
......@@ -81,47 +70,6 @@ then
exit 1;
fi
#--------------------------------------
# GENERATE DB schemas and diff files
#--------------------------------------
#last version (used for generating db diff files)
last_version=-1;
for version_A in ${versions[*]}
do
#main update file (used to create this version - it's a diff
#between base.sql and current version)
update_file=$SRC_DIR/db_0_to_$current_version".sql";
#now iterate through all versions
for file in `ls $DB_SCHEMA_DIR/$version_A | sort -V`;
do
if [ -f "$DB_SCHEMA_DIR/$version_A/$file" ]
then
#add differemce tp current db schema diff
printf "\n\n-- UPDATE $version_A/$file\n\n" >>$update_file;
cat $DB_SCHEMA_DIR/$version_A/$file >> $update_file;
#and now iterate again through all versions to add diffs
#between previous versions and current one
for version_B in ${versions[*]}
do
#update from version_B should contain all db changes that appeard
#after #version_B (so version_A must be later)
if versionCompLt $version_B $version_A
then
upd_file=$SRC_DIR/db_"$version_B"_to_$current_version".sql";
printf "\n\n-- UPDATE $version_A/$file\n\n" >>$upd_file;
cat $DB_SCHEMA_DIR/$version_A/$file >> $upd_file;
fi
done
fi
done
last_version=$version_A
done
#------------------------------------------
# Now we have all db schema diff files. Let's start preparing
# debian package
......
# shell snippet which extracts all available MINERVA versions from
# subdirectories available in DB_SCHEMA_DIR (typically
# `persist/src/db`) and generates database upgrade scripts (diff
# files)
# Precondition: the following variables have to be correctly initialised
# * DB_SCHEMA_DIR set to the directory containing database initialisation and upgrade sql commands
# * DBSCRIPT_DEST_DIR set to the directory that will be populated with database upgrade scripts
# Postcondition:
# * versions is set to the available MINERVA versions (bash array)
# * current_version is set to the latest available version
# * DBSCRIPT_DEST_DIR contains script to initialise the database from any version to the current version
#this variable will contain all available versions of the package
versions=();
#this is current (latest) version of the package
current_version=-1;
#find all available versions
for version in `ls "$DB_SCHEMA_DIR" | sort -V`;
do
if [ -d "$DB_SCHEMA_DIR/$version" ]
then
versions+=($version);
current_version=$version;
fi
done
#--------------------------------------
# GENERATE DB schemas and diff files
#--------------------------------------
versionCompLte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
versionCompLt() {
[ "$1" = "$2" ] && return 1 || versionCompLte $1 $2
}
#last version (used for generating db diff files)
for version_A in ${versions[*]}
do
#main update file (used to create this version - it's a diff
#between base.sql and current version)
update_file="$DBSCRIPT_DEST_DIR/db_0_to_${current_version}.sql";
#now iterate through all versions
for file in `ls "$DB_SCHEMA_DIR/$version_A" | sort -V`;
do
if [ -f "$DB_SCHEMA_DIR/$version_A/$file" ]
then
#add difference to current db schema diff
printf "\n\n-- UPDATE $version_A/$file\n\n" >> "$update_file";
cat "$DB_SCHEMA_DIR/$version_A/$file" >> "$update_file";
#and now iterate again through all versions to add diffs
#between previous versions and current one
for version_B in ${versions[*]}
do
#update from version_B should contain all db changes that appeared
#after #version_B (so version_A must be later)
if versionCompLt $version_B $version_A
then
upd_file="$DBSCRIPT_DEST_DIR/db_${version_B}_to_${current_version}.sql";
printf "\n\n-- UPDATE $version_A/$file\n\n" >> "$upd_file";
cat "$DB_SCHEMA_DIR/$version_A/$file" >> "$upd_file";
fi
done
fi
done
done
MINERVA installation instructions using RPM Package Manager
===========================================================
These instructions guide you through the installation process of
`MINERVA <https://git-r3lab.uni.lu/piotr.gawron/minerva>`_ on Red Hat
Enterprise Linux 7 or CentOS 7. The server will also host the database
required for the functioning of MINERVA.
.. note::
Content visualization of MINERVA platform is supported by Google
Maps API. Users of MINERVA platform are obliged to comply with the
`Google Maps/Google Earth APIs Terms of Service
<https://www.google.com/intl/en-US_US/help/terms_maps.html>`_.
Overview
--------
The main steps are
* Install `Oracle Java SE Development Kit 8 <http://www.oracle.com/technetwork/java/javase/downloads/index.html>`_.
* Install `PostgreSQL <https://www.postgresql.org/>`_ and set up a
database.
* Install and configure `Apache Tomcat <https://tomcat.apache.org/>`_.
* Install the MINERVA RPM.
Java SE Development Kit
-----------------------
Red Hat Enterprise Linux 7
``````````````````````````
Follow the instructions at https://access.redhat.com/solutions/732883
to install ``java-1.8.0-oracle``.
CentOS 7
````````
Follow the link for ``Java SE Development Kit 8`` at
`<http://www.oracle.com/technetwork/java/javase/downloads/index.html>`_,
download the latest RPM and install it with
.. code:: shell
yum install -y jdk-8uXXX-linux-x64.rpm
.. warning::
This way of installing Java does **not** ensure that security
updates are installed with ``yum update``, therefore you have to
establish a process to install such updates manually.
PostgreSQL
----------
Install PostgreSQL and initialise it with
.. code:: shell
yum install -y postgresql-server
postgresql-setup initdb
Ensure that the database authentication on IPv4 on ``localhost`` is
done with md5-based passwords by adding the following line to
``/var/lib/pgsql/data/pg_hba.conf``
.. code::
host all all 127.0.0.1/32 md5
Enable and start postgresql
.. code:: shell
systemctl enable postgresql
systemctl start postgresql
Create the MINERVA database user and the database
.. code:: shell
su - postgres -c "createuser -d -r -s map_viewer"
su - postgres -c "echo \"ALTER USER map_viewer WITH PASSWORD '123qweasdzxc';\"| psql"
su - postgres -c "createdb -O map_viewer map_viewer"
.. warning::
Currently the password for the database user ``map_viewer`` is
hardcoded, therefore make sure the database cannot be accessed
from distrusted hosts.
Apache Tomcat
-------------
Install and enable (don't start yet) Apache Tomcat with
.. code:: shell
yum install -y tomcat
systemctl enable tomcat
In ``/etc/sysconfig/tomcat``, adjust the memory settings, e.g.
.. code::
JAVA_OPTS="-Xms2048M -Xmx4096M"
Make sure to open the port (by default port 8080) to allow incoming
connections, e.g. using ``firewalld`` this can be accomplished with
.. code:: shell
firewall-cmd --zone=public --add-port=8080/tcp
.. warning::
Currently the administrator password of MINERVA is hardcoded,
therefore make sure the MINERVA cannot be accessed from distrusted
hosts until the password was changed.
MINERVA
-------
Install MINERVA using ``yum``
.. code:: shell
yum install -y minerva-X.Y.Z-1.el7.centos.noarch.rpm
and start tomcat
.. code:: shell
systemctl start tomcat
Now point your browser to the newly installed service, e.g. on a local
network this could be `<http://192.168.0.42:8080/minerva/>`_.
.. warning::
This way of installing MINERVA does **not** ensure that security
updates are installed with ``yum update``, therefore you have to
establish a process to install such updates manually.
#!/bin/bash
set -e
MINERVA_SRC_DIR="$(dirname "$(dirname "$0")")"
# where generated files will be written
RPMBUILD_TEMP="${RPMBUILD_TEMP:-$MINERVA_SRC_DIR/rpm/rpmbuildtemp}"
if [[ "$RPMBUILD_TEMP" =~ ' ' ]]; then
echo "RPMBUILD_TEMP contains whitespace: '$RPMBUILD_TEMP'"
echo "This is not allowed. Please provide a different directory to create the RPM with"
echo " RPMBUILD_TEMP=/path/without/whitespace/ \"$0\""
exit 1
fi
# current date (for automatic changelog)
CURDATE=$(date +"%a %b %d %Y")
# file that should be deployed on tomcat
TOMCAT_FILE="$MINERVA_SRC_DIR/web/target/web-1.0.war"
# file with bash code generating DB schema diffs for different versions
dbschemadiff="$MINERVA_SRC_DIR/management_scripts/db_schema_and_diff.sh"
# directory with database schema
DB_SCHEMA_DIR="$MINERVA_SRC_DIR/persist/src/db"
# destination directory for database upgrade scripts
DBSCRIPT_DEST_DIR="$RPMBUILD_TEMP/BUILD/sql"
# clean build directories
rm -rf "$RPMBUILD_TEMP"
# create directory
mkdir -p "$RPMBUILD_TEMP/"{BUILD,SPECS}
# copy war file and other files
cp "$TOMCAT_FILE" "$RPMBUILD_TEMP/BUILD/minerva.war"
cp "$MINERVA_SRC_DIR/README.md" "$MINERVA_SRC_DIR/CHANGELOG" "$MINERVA_SRC_DIR/rpm/INSTALL.rst" "$MINERVA_SRC_DIR/rpm/logrotate_minerva" "$RPMBUILD_TEMP/BUILD"
mkdir -p "$DBSCRIPT_DEST_DIR"
# copy base sql schema
cp "$DB_SCHEMA_DIR/base.sql" "$DBSCRIPT_DEST_DIR/db_0.sql"
# set $versions and $current_version; generate upgrade scripts in DBSCRIPT_DEST_DIR
source "$dbschemadiff"
# create RPM spec file
cp "$MINERVA_SRC_DIR/rpm/minerva.spec.in" "$RPMBUILD_TEMP/SPECS/minerva.spec"
sed -i "s/__CURRENT_VERSION__/$current_version/g" "$RPMBUILD_TEMP/SPECS/minerva.spec"
sed -i "s/__DATE__/$CURDATE/g" "$RPMBUILD_TEMP/SPECS/minerva.spec"
# build RPM
RPMBUILD_TEMP_ABS="$(readlink -f "$RPMBUILD_TEMP")"
echo "****** Building miverva $current_version RPM in $RPMBUILD_TEMP_ABS ****** "
set -x
rpmbuild -bb --define "_topdir $RPMBUILD_TEMP_ABS" "$RPMBUILD_TEMP_ABS/SPECS/minerva.spec"
set +x
echo "****** Finished building RPM ****** "
/var/log/tomcat/minerva.txt {
copytruncate
size 32k
weekly
dateext
rotate 52
compress
missingok
create 0640 tomcat tomcat
}
Name: minerva
Version: __CURRENT_VERSION__
Release: 1%{?dist}
Summary: Platform for visualization and curation of molecular interaction networks
License: AGPLv3
URL: http://r3lab.uni.lu/web/minerva-website/
Source0: https://git-r3lab.uni.lu/piotr.gawron/minerva/repository/archive.tar.gz?ref=v%{version}
Requires: tomcat, postgresql
BuildArch: noarch
%description
Web application for visualization, exploration and management of
molecular networks encoded in SBGN-compliant format. The resource is
used and managed via a webbrowser.
%pre -p /bin/bash
# check that postgres is started and tomcat is stopped, otherwise abort installation/upgrade
if ! $(systemctl -q is-active postgresql); then
echo "postgresql not running, aborting installation/upgrade of minerva" >&2
exit -1
fi
if $(systemctl -q is-active tomcat); then
echo "tomcat is running, aborting installation/upgrade of minerva" >&2
exit -1
fi
# make sure the user `map_viewer` has the required permissions
attributes_map_viewer=$(su - postgres -c "psql -F $'\t' --no-align -t -c '\du map_viewer'" | cut -f 2)
if ! [[ $attributes_map_viewer == *"Superuser"* ]] || ! [[ $attributes_map_viewer == *"Create role"* ]] || ! [[ $attributes_map_viewer == *"Create DB"* ]]; then
echo "Postgres user map_viewer does not exist or does not have the required attributes." >&2
echo "Make sure to create map_viewer with the permission 'Superuser, Create role, Create DB'." >&2
echo "Attributes are: '$attributes_map_viewer'" >&2
echo "Aborting installation/upgrade of minerva." >&2
exit -1
fi
# make sure the database map_viewer exists
if ! su - postgres -c "psql --dbname map_viewer -q -c '\q'" 2> /dev/null; then
echo "Database map_viewer does not exist, aborting installation/upgrade of minerva." >&2
exit -1
fi
%preun -p /bin/bash
# save version information of the old package to make sure we run the correct DB-update script after installation
if [ $1 == 1 ]; then
mkdir -p %{_sharedstatedir}/rpm-state/%{name}
echo -n %{version} > %{_sharedstatedir}/rpm-state/%{name}/OLD_VERSION
fi
%posttrans -p /bin/bash
LOGFILE=%{_localstatedir}/log/minerva-install.log
if [ -e %{_sharedstatedir}/rpm-state/%{name}/OLD_VERSION ]; then
OLD_VERSION=$(cat %{_sharedstatedir}/rpm-state/%{name}/OLD_VERSION)
echo $(date) "Upgrading minerva from $OLD_VERSION to %{version}" >> $LOGFILE
if [ ! -e %{_datadir}/%{name}/schema/db_${OLD_VERSION}_to_%{version}.sql ]; then
echo "ERROR: missing DB-update script %{_datadir}/%{name}/schema/db_${OLD_VERSION}_to_%{version}.sql" >&2
exit -1
fi
su - postgres -c "psql map_viewer -f %{_datadir}/%{name}/schema/db_${OLD_VERSION}_to_%{version}.sql" >> $LOGFILE 2>&1
rm -f %{_sharedstatedir}/rpm-state/%{name}/OLD_VERSION
rmdir %{_sharedstatedir}/rpm-state/%{name}
else
echo $(date) "Installing minerva %{version}" >> $LOGFILE
if [ $(su - postgres -c "psql --dbname map_viewer -F $'\t' --no-align -t -c '\dt'" | wc -l) -gt 51 ]; then
echo "The database map_viewer is not empty, aborting initialisation of database." >&2
echo "The database map_viewer is not empty, aborting initialisation of database." >> $LOGFILE
exit -1
fi
# install base version of the framework
su - postgres -c "psql map_viewer -f %{_datadir}/%{name}/schema/db_0.sql" >> $LOGFILE 2>&1
# install patch to current version
su - postgres -c "psql map_viewer -f %{_datadir}/%{name}/schema/db_0_to_%{version}.sql" >> $LOGFILE 2>&1
fi
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/%{_datadir}/%{name}/schema
install -m 0644 sql/*.sql %{buildroot}/%{_datadir}/%{name}/schema
install -m 0644 %{name}.war %{buildroot}/%{_datadir}/%{name}/%{name}.war
mkdir -p %{buildroot}/%{_sysconfdir}/logrotate.d
install -m 0644 logrotate_minerva %{buildroot}/%{_sysconfdir}/logrotate.d/minerva
mkdir -p %{buildroot}/%{_sharedstatedir}/tomcat/webapps
ln -s %{_datadir}/%{name}/%{name}.war %{buildroot}/%{_sharedstatedir}/tomcat/webapps/
%files
%defattr(-,root,root,-)
%doc README.md CHANGELOG INSTALL.rst
%{_datadir}/%{name}/%{name}.war
%{_datadir}/%{name}/schema/*
%config(noreplace) %{_sysconfdir}/logrotate.d/minerva
%attr(-,tomcat,tomcat) %{_sharedstatedir}/tomcat/webapps/%{name}.war
%changelog
* __DATE__ - %{version}-%{release}
- Automatically packaged
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment