Cmdbuild 3.1 installation on RedHat or CentOs 7

I believe that some people might find this small script useful.

Anyway, watch out the variables, also keep in mind that not everything as been set as variable. There are no checks on existing things (except on postgres listening) and it will execute commands anyway, it should be idempotent though..


#!/usr/bin/env bash
set -x
install_folder="/opt"
postgresql_server="127.0.0.1"
database_name="cmdbuild"
cmdbuild_user_name="cmdbuild"
cmdbuild_user_pass="cmdbuild"
cmdbuild_super_user="scmdbuild"
cmdbuild_super_pass="scmdbuild"
tomcat_version="8.5.46"
java_version="1.8.0"
postgres_version="96"
cmdbuild_version="3.1.1"
tomcat_user="tomcat"
tomcat_group="tomcat"

yum -y update
systemctl stop firewalld 
systemctl disable firewalld
yum -y install nc wget centos-release-scl java-${java_version}-openjdk.x86_64 rh-postgresql${postgres_version}-postgresql rh-postgresql${postgres_version}-syspaths.x86_64

ln -s /opt/rh/rh-postgresql${postgres_version}/root/usr/lib64/libpq.so.rh-postgresql96-5.9 /opt/rh/rh-postgresql96/root/usr/lib64/libpq.so.5
ln -s /opt/rh/rh-postgresql${postgres_version}/root/usr/lib64/libpq.so.5 /usr/lib64/libpq.so.5

nc -z ${postgresql_server} 5432 > /dev/null
if [ $? -eq 0 ]; then
    echo -e "Test tcp connection to the db suceeded"
else
    echo -e "The connection to the database ${database_name} to the server ${postgresql_server} didn't work, please check the config."
    exit 1
fi

groupadd ${tomcat_group}
useradd -M -s /sbin/nologin -g ${tomcat_group} -d ${install_folder}/tomcat ${tomcat_user}

#tomcat
cd ~
wget -O /var/tmp/apache-tomcat-${tomcat_version}.tar.gz //www-eu.apache.org/dist/tomcat/tomcat-8/v${tomcat_version}/bin/apache-tomcat-${tomcat_version}.tar.gz 
mkdir -p ${install_folder}/tomcat
tar -xzf /var/tmp/apache-tomcat-${tomcat_version}.tar.gz -C ${install_folder}/tomcat --strip-components=1
chgrp -R ${tomcat_user} ${install_folder}/tomcat
chmod -R g+r ${install_folder}/tomcat/conf/*
chmod g+rx ${install_folder}/tomcat/conf
chown -R ${tomcat_user} ${install_folder}/tomcat/logs/
chmod -R g+w ${install_folder}/tomcat/work
chmod -R g+w ${install_folder}/tomcat/temp
chmod -R g+w ${install_folder}/tomcat/logs
chmod -R g+r ${install_folder}/tomcat/conf
chmod -R g+w ${install_folder}/tomcat/webapps

# Systemd
cat > /etc/systemd/system/tomcat.service <<EOF
# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=${install_folder}/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=${install_folder}/tomcat
Environment=CATALINA_BASE=${install_folder}/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=${install_folder}/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 \$MAINPID
User=${tomcat_user}
Group=${tomcat_group}
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload 
systemctl start tomcat
systemctl enable tomcat
systemctl stop tomcat

rm -rf ${install_folder}/tomcat/webapps/*


#Download cmdbuild
mkdir -p /var/tmp/f
cd /var/tmp/f 
wget -O /var/tmp/cmdbuild-${cmdbuild_version}.war //sourceforge.net/projects/cmdbuild/files/${cmdbuild_version}/cmdbuild-${cmdbuild_version}.war/download?use_mirror=netcologne# 
wget -O /var/tmp/f/cmdbuild-${cmdbuild_version}-resources.tar.gz //sourceforge.net/projects/cmdbuild/files/${cmdbuild_version}/cmdbuild-${cmdbuild_version}-resources.tar.gz/download# 

cp /var/tmp/cmdbuild-${cmdbuild_version}.war ${install_folder}/tomcat/webapps/ROOT.war
systemctl start tomcat
sleep 20
systemctl stop tomcat

mkdir -p ${install_folder}/tomcat/conf/ROOT


cat <<EOF > "${install_folder}"/tomcat/conf/ROOT/database.conf 
db.url=jdbc:postgresql://${postgresql_server}:5432/${database_name}
db.username=${cmdbuild_user_name}
db.password=${cmdbuild_user_pass}
db.admin.username=${cmdbuild_super_user}
db.admin.password=${cmdbuild_super_pass}
EOF

chown ${tomcat_user}. ${install_folder}/tomcat/conf/ROOT/database.conf

cd /var/tmp/f
tar -xzf /var/tmp/f/cmdbuild-${cmdbuild_version}-resources.tar.gz
cp /var/tmp/f/tomcat-libs/postgresql-*.jar ${install_folder}/tomcat/lib/
chown ${tomcat_user}. ${install_folder}/tomcat/lib/postgresql-*.jar

systemctl stop tomcat
bash ${install_folder}/tomcat/webapps/ROOT/cmdbuild.sh dbconfig create empty -configfile ${install_folder}/tomcat/conf/cmdbuild-${cmdbuild_version}/database.conf
systemctl start tomcat

This also need a machine running postgresql 9.6, for which I Made another script, just for you 🙂

#!/usr/bin/env bash
##################################
install_folder="/usr/share/"       #  C
cmdbuild_user_name="cmdbuild"      #  O
cmdbuild_user_pass="cmdbuild"      #  N
cmdbuild_super_user="scmdbuild"    #  F
cmdbuild_super_pass="scmdbuild"    #  I
sql_queries_path="/var/tmp/"       #  G
cmdbuild_sql_file="cmdbuild.sql"   #  !
scmdbuild_sql_file="scmdbuild.sql" #  @
cmdbuild_db_name="cmdbuild"        #  @

################################
cd ${sql_queries_path}

yum -y install centos-release-scl
yum -y install rh-postgresql96-postgresql-server rh-postgresql96-postgresql
yum -y install rh-postgresql96-syspaths.x86_64

postgresql-setup --initdb
systemctl enable postgresql
systemctl start postgresql

# If tomcat and postgres are running on the same host, then comment the following two lines
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --reload

echo -e "CREATE USER ${cmdbuild_user_name} WITH encrypted password '"${cmdbuild_user_pass}"';" > ${sql_queries_path}/${cmdbuild_sql_file}
echo -e "CREATE USER ${cmdbuild_super_user} WITH encrypted password '"${cmdbuild_super_pass}"';" > ${sql_queries_path}/${scmdbuild_sql_file}
echo -e "ALTER USER ${cmdbuild_super_user} WITH SUPERUSER;" >> ${sql_queries_path}/${scmdbuild_sql_file}

sudo -u postgres psql --file="${sql_queries_path}/${cmdbuild_sql_file}"
sudo -u postgres psql --file="${sql_queries_path}/${scmdbuild_sql_file}"

rm -rf ${sql_queries_path}/${cmdbuild_sql_file}
rm -rf ${sql_queries_path}/${scmdbuild_sql_file}

sed -i 's/# IPv4 local connections:/# IPv4 local connections:\n host         all         all    0.0.0.0\/0       md5/g' /var/opt/rh/rh-postgresql96/lib/pgsql/data/pg_hba.conf
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '0.0.0.0'/g" /var/opt/rh/rh-postgresql96/lib/pgsql/data/postgresql.conf

systemctl restart postgresql



Enjoy the time I’m saving you and please report back if anything goes wrong.

Giuseppe

 
(Visited 74 times, 1 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

8 thoughts on “Cmdbuild 3.1 installation on RedHat or CentOs 7”

  1. Hi Giuseppe,
    When I was trying to install CMDBuild 3.1.1, with prerequisites such as Tomcat 8.5.39, Postgre 9.5, Java 1.8 installed, I cannot get CMDBuild started from Tomcat app manager. It says “FAIL-Application at context path [/cmdbuild-3.1.1] could not be started.

    However, if i installed cmdbuild 2.5.1, it can start and run without problems.

    What could be the issue?

      1. Some update, i installed tomcat 8.5.45, postgresql 9.6 with pgadmin 4 via guided installer from postgre website, and Java 1.80. Compiled database with ‘bash command’, copied database.conf, removed # at the front, as found in cmdbuild technical guide.

        Somehow, I managed to get cmdbuild 3.1.1 installed in tomcat 8.5.45 and started. I cannot get into login page.

        In cmdbuild3 log, there is a statement that says :

        2019-09-30 16:59:29.554 [sys:boot] INFO o.cmdbuild.minions.SystemServiceImpl – check patch manager
        2019-09-30 16:59:29.634 [sys:boot] ERROR o.cmdbuild.minions.SystemServiceImpl – system startup error
        java.lang.IllegalArgumentException: the datasource is not configured!
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java:135) ~[guava-23.0.jar:na]
        at

        I cannot locate datasource.

        1. Ok I think i know what’s happening here.

          Going through the script on this page, you can see that at a certain point a configuration file is created in ${install_folder}”/tomcat/conf/ROOT/database.conf
          This file is picked up by tomcat at startup as long as the folder in ${install_folder}/tomcat/conf/ is called the same way as the webapp, this case ROOT.
          This is Tomcat specific.

          The configuration file is populated using the variables set at the beginning of the script.
          mkdir -p ${install_folder}/tomcat/conf/ROOT

          cat < "${install_folder}"/tomcat/conf/ROOT/database.conf
          db.url=jdbc:postgresql://${postgresql_server}:5432/${database_name}
          db.username=${cmdbuild_user_name}
          db.password=${cmdbuild_user_pass}
          db.admin.username=${cmdbuild_super_user}
          db.admin.password=${cmdbuild_super_pass}
          EOF

          This is what is used by cmdbuild install script to set the datasource up.
          Let me know if this helps.
          Giuseppe

          1. Hi Giuseppe,
            I managed to get it running. But I not sure what I did, maybe entering some of your scripts, updating CentOS 7 or after reboot.

            I wonder if I can get DMS Alfresco running, use to store documents.

            Chai

  2. I just got CMDBuild 3.1.1 up. I not sure what I did recently. Maybe updating CentOS or typing some script that you had given above.

    By the way, have you tried to set up DMS Alfresco? That will be useful to attach documents.

    Chai

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.