Cmdbuild 3.1 installation on CentOs7

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.45"
java_version="1.8.0"
postgres_version="96"
cmdbuild_version="3.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 13 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.

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.