Install script to deploy axelor from sources

Hi, as I struggled about running axelor from source at the first time, I thought about writting a script to deploy any recent version of axelor from sources on ubuntu, it might need improvement, feel free to collaborate to make it better.

I did not try it yet.

#!/bin/bash

# Variables
POSTGRES_PASSWORD="your_postgres_password"
AXELOR_DB_USER="axeloruserdb"
AXELOR_DB_PASSWORD="your_axelor_db_password"
AXELOR_DB_NAME="axelordb"
GRADLE_VERSION="7.4.2"
TOMCAT_VERSION="9.0.85"
AXELOR_VERSION="v7.2.6"
AXELOR_CONFIG_PATH="/opt/tomcat/webapps/axelor-erp-$AXELOR_VERSION/WEB-INF/classes/axelor-config.properties"
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

# Update System
sudo apt-get update

# Install PostgreSQL
sudo apt-get install -y postgresql postgresql-contrib

# Start and Enable PostgreSQL Service
sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service

# Set Password for PostgreSQL User
sudo -u postgres psql -c "ALTER USER postgres PASSWORD '$POSTGRES_PASSWORD';"

# Create Axelor Database User
sudo -u postgres psql -c "CREATE USER $AXELOR_DB_USER WITH SUPERUSER PASSWORD '$AXELOR_DB_PASSWORD';"

# Create Axelor Database
sudo -u postgres psql -c "CREATE DATABASE $AXELOR_DB_NAME OWNER $AXELOR_DB_USER;"

# Configure pg_hba.conf for Local Connections
PG_HBA_PATH=$(sudo -u postgres psql -t -P format=unaligned -c 'SHOW hba_file;')
sudo sed -i "s/local   all             all                                     peer/local   all             all                                     md5/" $PG_HBA_PATH

# Reload PostgreSQL to Apply Changes
sudo systemctl reload postgresql

# Install JDK
sudo apt-get install -y openjdk-11-jdk

# Download and Install Gradle
wget "https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip"
sudo unzip -d /opt/gradle "gradle-$GRADLE_VERSION-bin.zip"
echo "export GRADLE_HOME=/opt/gradle/gradle-$GRADLE_VERSION" >> ~/.bashrc
echo "export PATH=\$PATH:\$GRADLE_HOME/bin" >> ~/.bashrc

# Set JAVA_HOME
echo "export JAVA_HOME=$JAVA_HOME" >> ~/.bashrc
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.bashrc
source ~/.bashrc

# Download and Install Tomcat
wget "https://downloads.apache.org/tomcat/tomcat-9/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz"
sudo mkdir -p /opt/tomcat
sudo tar xzvf "apache-tomcat-$TOMCAT_VERSION.tar.gz" -C /opt/tomcat --strip-components=1

# Create Tomcat User
sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

# Change Tomcat Directory Permissions
sudo chown -R tomcat: /opt/tomcat

# Set up Tomcat as a Service
cat << EOF | sudo tee /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=$JAVA_HOME
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
EOF

# Reload System Daemon and Start Tomcat
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat

# Allow Tomcat Port in UFW
sudo ufw allow 8080/tcp

# Download and Deploy Axelor WAR
sudo wget "https://github.com/axelor/axelor-open-suite/releases/download/$AXELOR_VERSION/axelor-erp-$AXELOR_VERSION.war" -P /opt/tomcat/webapps/

# Wait for Tomcat to deploy Axelor WAR
echo "Waiting for Tomcat to deploy Axelor WAR..."
sleep 90

# Configure Axelor Database Settings in axelor-config.properties
sudo sed -i "s/db.default.url = .*/db.default.url = jdbc:postgresql:\/\/localhost:5432\/$AXELOR_DB_NAME/" $AXELOR_CONFIG_PATH
sudo sed -i "s/db.default.user = .*/db.default.user = $AXELOR_DB_USER/" $AXELOR_CONFIG_PATH
sudo sed -i "s/db.default.password = .*/db.default.password = $AXELOR_DB_PASSWORD/" $AXELOR_CONFIG_PATH

# Restart Tomcat
sudo systemctl restart tomcat

echo "Axelor ERP installation and configuration completed."

Notes

  1. Customize variables (POSTGRES_PASSWORD, GRADLE_VERSION, etc.) as needed.
  2. Save the above script as install_axelor.sh.
  3. Give execute permission: chmod +x install_axelor.sh.
  4. Run the script: ./install_axelor.sh.

Once the script completes, you should be able to access to Axelor at

http://<your-server-ip>:8080/axelor-erp-vYOUR_AXELOR_VERSION

Hi, I tried to install and deploy Axelor ERP, but at the end of the installation, I recive this error message who says axelor v8.0.6 was not found when it’s available in the Github on Axelor. I would deploy latest version. how proceed to this ?

thanks
Capture d'écran 2024-05-03 135654