2023-12-19 14:42:05 +00:00
#!/bin/bash
2024-07-05 15:22:41 +00:00
set -e
2023-12-19 14:42:05 +00:00
while [ " $1 " != "" ] ; do
2024-07-05 15:22:41 +00:00
case $1 in
-ds | --download-scripts )
if [ " $2 " != "" ] ; then
DOWNLOAD_SCRIPTS = $2
shift
fi
; ;
-arg | --arguments )
if [ " $2 " != "" ] ; then
ARGUMENTS = $2
shift
fi
; ;
2023-12-19 14:42:05 +00:00
2024-07-05 15:22:41 +00:00
-li | --local-install )
if [ " $2 " != "" ] ; then
LOCAL_INSTALL = $2
shift
fi
; ;
2023-12-19 14:42:05 +00:00
2024-07-05 15:22:41 +00:00
-tr | --test-repo )
if [ " $2 " != "" ] ; then
TEST_REPO_ENABLE = $2
shift
fi
; ;
esac
shift
2023-12-19 14:42:05 +00:00
done
export TERM = xterm-256color^M
function common::get_colors( ) {
2024-07-05 15:22:41 +00:00
export LINE_SEPARATOR = "-----------------------------------------"
export COLOR_BLUE = $'\e[34m' COLOR_GREEN = $'\e[32m' COLOR_RED = $'\e[31m' COLOR_RESET = $'\e[0m' COLOR_YELLOW = $'\e[33m'
2023-12-19 14:42:05 +00:00
}
#############################################################################################
# Checking available resources for a virtual machine
# Globals:
# None
# Arguments:
# None
# Outputs:
# None
#############################################################################################
function check_hw( ) {
2024-07-05 15:22:41 +00:00
echo " ${ COLOR_RED } $( free -h) ${ COLOR_RESET } "
echo " ${ COLOR_RED } $( nproc) ${ COLOR_RESET } "
2023-12-19 14:42:05 +00:00
}
2024-05-21 07:06:44 +00:00
#############################################################################################
# Add nexus repositories for test packages for .deb and .rpm packages
# Globals: None
# Arguments: None
# Outputs: None
#############################################################################################
function add-repo-deb( ) {
mkdir -p -m 700 $HOME /.gnupg
echo "deb [signed-by=/usr/share/keyrings/onlyoffice.gpg] https://nexus.onlyoffice.com/repository/4testing-debian stable main" | \
sudo tee /etc/apt/sources.list.d/onlyoffice4testing.list
curl -fsSL https://download.onlyoffice.com/GPG-KEY-ONLYOFFICE | \
gpg --no-default-keyring --keyring gnupg-ring:/usr/share/keyrings/onlyoffice.gpg --import
chmod 644 /usr/share/keyrings/onlyoffice.gpg
}
function add-repo-rpm( ) {
cat > /etc/yum.repos.d/onlyoffice4testing.repo <<END
[ onlyoffice4testing]
name = onlyoffice4testing repo
baseurl = https://nexus.onlyoffice.com/repository/centos-testing/4testing/main/noarch
gpgcheck = 1
enabled = 1
gpgkey = https://download.onlyoffice.com/GPG-KEY-ONLYOFFICE
END
}
2023-12-19 14:42:05 +00:00
#############################################################################################
# Prepare vagrant boxes like: set hostname/remove postfix for DEB distributions
# Globals:
# None
# Arguments:
# None
# Outputs:
# ☑ PREPAVE_VM: **<prepare_message>**
#############################################################################################
function prepare_vm( ) {
2024-05-21 07:06:44 +00:00
if [ -f /etc/os-release ] ; then
source /etc/os-release
case $ID in
ubuntu)
[ [ " ${ TEST_REPO_ENABLE } " = = 'true' ] ] && add-repo-deb
; ;
debian)
2024-07-05 15:22:41 +00:00
[ " $VERSION_CODENAME " = = "bookworm" ] && apt-get update -y && apt install -y curl gnupg
apt-get remove postfix -y && echo " ${ COLOR_GREEN } ☑ PREPAVE_VM: Postfix was removed ${ COLOR_RESET } "
2024-05-21 07:06:44 +00:00
[ [ " ${ TEST_REPO_ENABLE } " = = 'true' ] ] && add-repo-deb
; ;
fedora)
[ [ " ${ TEST_REPO_ENABLE } " = = 'true' ] ] && add-repo-rpm
; ;
centos)
2024-07-05 15:22:41 +00:00
[ " $VERSION_ID " = = "8" ] && sed -i 's|^mirrorlist=|#&|; s|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|' /etc/yum.repos.d/CentOS-*
2024-05-21 07:06:44 +00:00
[ [ " ${ TEST_REPO_ENABLE } " = = 'true' ] ] && add-repo-rpm
yum -y install centos*-release
; ;
*)
echo " ${ COLOR_RED } Failed to determine Linux dist ${ COLOR_RESET } " ; exit 1
; ;
esac
else
echo " ${ COLOR_RED } File /etc/os-release doesn't exist ${ COLOR_RESET } " ; exit 1
2023-12-19 14:42:05 +00:00
fi
# Clean up home folder
rm -rf /home/vagrant/*
2024-07-05 15:22:41 +00:00
[ -d /tmp/docspace ] && mv /tmp/docspace/* /home/vagrant
2023-12-19 14:42:05 +00:00
echo '127.0.0.1 host4test' | sudo tee -a /etc/hosts
echo " ${ COLOR_GREEN } ☑ PREPAVE_VM: Hostname was setting up ${ COLOR_RESET } "
}
#############################################################################################
# Install docspace and then healthcheck
# Globals:
# None
# Arguments:
# None
# Outputs:
# Script log
#############################################################################################
function install_docspace( ) {
2024-07-05 15:22:41 +00:00
[ [ " ${ DOWNLOAD_SCRIPTS } " = = 'true' ] ] && wget https://download.onlyoffice.com/docspace/docspace-install.sh || sed 's/set -e/set -xe/' -i *.sh
bash docspace-install.sh package ${ ARGUMENTS } || { echo "Exit code non-zero. Exit with 1." ; exit 1; }
echo "Exit code 0. Continue..."
2023-12-19 14:42:05 +00:00
}
#############################################################################################
# Healthcheck function for systemd services
# Globals:
2024-07-05 15:22:41 +00:00
# None
2023-12-19 14:42:05 +00:00
# Arguments:
# None
# Outputs:
# Message about service status
#############################################################################################
function healthcheck_systemd_services( ) {
2024-07-05 15:22:41 +00:00
for service in ${ SERVICES_SYSTEMD [@] } ; do
[ [ " $service " = = "docspace-migration-runner.service" ] ] && continue ;
2023-12-19 14:42:05 +00:00
if systemctl is-active --quiet ${ service } ; then
echo " ${ COLOR_GREEN } ☑ OK: Service ${ service } is running ${ COLOR_RESET } "
else
echo " ${ COLOR_RED } ⚠ FAILED: Service ${ service } is not running ${ COLOR_RESET } "
SYSTEMD_SVC_FAILED = "true"
fi
done
}
#############################################################################################
# Set output if some services failed
# Globals:
# None
# Arguments:
# None
# Outputs:
# ⚠ ⚠ ATTENTION: Some sevices is not running ⚠ ⚠
# Returns
# 0 if all services is start correctly, non-zero if some failed
#############################################################################################
function healthcheck_general_status( ) {
if [ ! -z " ${ SYSTEMD_SVC_FAILED } " ] ; then
echo " ${ COLOR_YELLOW } ⚠ ⚠ ATTENTION: Some sevices is not running ⚠ ⚠ ${ COLOR_RESET } "
exit 1
fi
}
#############################################################################################
# Get logs for all services
# Globals:
2024-07-05 15:22:41 +00:00
# None
2023-12-19 14:42:05 +00:00
# Arguments:
# None
# Outputs:
# Logs for systemd services
# Returns:
# none
# Commentaries:
# This function succeeds even if the file for cat was not found. For that use ${SKIP_EXIT} variable
#############################################################################################
function services_logs( ) {
2024-07-05 15:22:41 +00:00
SERVICES_SYSTEMD = ( $( awk '/SERVICE_NAME=\(/{flag=1; next} /\)/{flag=0} flag' "build.sh" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed 's/^/docspace-/' | sed 's/$/.service/' ) )
SERVICES_SYSTEMD += ( "ds-converter.service" "ds-docservice.service" "ds-metrics.service" )
2023-12-19 14:42:05 +00:00
for service in ${ SERVICES_SYSTEMD [@] } ; do
2024-07-05 15:22:41 +00:00
echo $LINE_SEPARATOR && echo " ${ COLOR_GREEN } Check logs for systemd service: $service ${ COLOR_RESET } " && echo $LINE_SEPARATOR
journalctl -u $service -n 30 || true
2023-12-19 14:42:05 +00:00
done
2024-07-05 15:22:41 +00:00
local DOCSPACE_LOGS_DIR = "/var/log/onlyoffice/docspace"
local DOCUMENTSERVER_LOGS_DIR = "/var/log/onlyoffice/documentserver"
2023-12-19 14:42:05 +00:00
2024-07-05 15:22:41 +00:00
for LOGS_DIR in " ${ DOCSPACE_LOGS_DIR } " " ${ DOCUMENTSERVER_LOGS_DIR } " ; do
echo $LINE_SEPARATOR && echo " ${ COLOR_YELLOW } Check logs for $( basename " ${ LOGS_DIR } " | tr '[:lower:]' '[:upper:]' ) ${ COLOR_RESET } " && echo $LINE_SEPARATOR
2023-12-19 14:42:05 +00:00
2024-07-05 15:22:41 +00:00
find " ${ LOGS_DIR } " -type f -name "*.log" ! -name "*sql*" ! -name "*nginx*" | while read -r FILE; do
echo $LINE_SEPARATOR && echo " ${ COLOR_GREEN } Logs from file: ${ FILE } ${ COLOR_RESET } " && echo $LINE_SEPARATOR
tail -30 " ${ FILE } " || true
done
done
2023-12-19 14:42:05 +00:00
}
main( ) {
common::get_colors
prepare_vm
check_hw
install_docspace
sleep 120
services_logs
healthcheck_systemd_services
healthcheck_general_status
}
main