setup log file and supported distro checks.

use wait_for_bootstrapping as function
This commit is contained in:
Luis Guzmán 2023-12-05 02:45:47 -06:00
parent e9ec4fcdde
commit be58ea1f0e
1 changed files with 68 additions and 9 deletions

View File

@ -5,6 +5,22 @@
# T&M Hansson IT AB © - 2022, https://www.hanssonit.se/ # T&M Hansson IT AB © - 2022, https://www.hanssonit.se/
# GPLv3 or later. # GPLv3 or later.
# #
{
echo "Started at $(date +'%Y-%m-%d %H:%M:%S')" >> opensearch-installer.log
while getopts m: option
do
case "${option}"
in
m) MODE=${OPTARG};;
\?) echo "Usage: sudo bash ./$0 [-m debug]" && exit;;
esac
done
#DEBUG
if [ "$MODE" = "debug" ]; then
set -x
fi
# Reset # Reset
Color_Off='\e[0m' # Text Reset Color_Off='\e[0m' # Text Reset
@ -18,6 +34,9 @@ Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan Cyan='\e[0;36m' # Cyan
MEM_AVAILABLE="$(grep MemTotal /proc/meminfo| grep -o '[0-9]\+')" MEM_AVAILABLE="$(grep MemTotal /proc/meminfo| grep -o '[0-9]\+')"
DIST=$(lsb_release -sc)
TODAY=$(date +%s)
NEXT_LTS_DATE=$(date -d 2024-04-01 +%s)
OPNSDIR="/opt/opensearch" OPNSDIR="/opt/opensearch"
INDEX_USER="$(tr -dc '[:lower:]' < /dev/urandom | fold -w 24 | head -n1)" INDEX_USER="$(tr -dc '[:lower:]' < /dev/urandom | fold -w 24 | head -n1)"
OPNSREST="$(tr -dc "a-zA-Z0-9" < /dev/urandom | fold -w 32 | head -n1)" OPNSREST="$(tr -dc "a-zA-Z0-9" < /dev/urandom | fold -w 32 | head -n1)"
@ -27,6 +46,14 @@ fts_node="fts_os-node"
max_map_count="512000" max_map_count="512000"
NL="$(printf '\n ')" NL="$(printf '\n ')"
rename_distro() {
if [ "$DIST" = "$1" ]; then
DIST="$2"
fi
}
#Trisquel distro upstream referencing.
rename_distro nabia focal
rename_distro aramo jammy
printwc() { printwc() {
printf "%b$2%b" "$1" "${Color_Off}" printf "%b$2%b" "$1" "${Color_Off}"
} }
@ -82,6 +109,14 @@ while [ $secs -gt 0 ]; do
: $((secs--)) : $((secs--))
done done
} }
wait_for_bootstrapping() {
if [ "$(nproc)" -gt 2 ]
then
countdown "Waiting for Docker bootstrapping..." "30"
else
countdown "Waiting for Docker bootstrapping..." "60"
fi
}
#Check if user is root #Check if user is root
if ! [ "$(id -u)" = 0 ]; then if ! [ "$(id -u)" = 0 ]; then
@ -89,6 +124,26 @@ if ! [ "$(id -u)" = 0 ]; then
exit 0 exit 0
fi fi
printf "\nOS: %s" "$(lsb_release -sd)"
if [ "$DIST" = "focal" ] || \
[ "$DIST" = "jammy" ]; then
printf "\nGood, this is a supported platform!"
else
printf "\nSorry, this platform is not supported... exiting"
exit
fi
# Suggest 22.04 LTS release over 20.04 in April 2024
if [ "$DIST" = "focal" ]; then
if [ "$TODAY" -gt "$NEXT_LTS_DATE" ]; then
echo " > $(lsb_release -sc), even when it's compatible and functional."
echo -n " We suggest to use the next (LTS) release, for longer"
echo " support and security reasons."
read -n 1 -s -r -p "Press any key to continue..."$'\n'
else
echo "Focal is supported."
fi
fi
# Check update # Check update
apt-get update -q2 apt-get update -q2
@ -313,13 +368,7 @@ print_title "Launch opensearch via docker-compose"
cd $OPNSDIR cd $OPNSDIR
docker-compose up -d docker-compose up -d
# Wait for bootstrapping wait_for_bootstrapping
if [ "$(nproc)" -gt 2 ]
then
countdown "Waiting for Docker bootstrapping..." "30"
else
countdown "Waiting for Docker bootstrapping..." "60"
fi
# Make sure password setup is enforced. # Make sure password setup is enforced.
docker-compose exec fts_os-node \ docker-compose exec fts_os-node \
@ -337,7 +386,17 @@ docker-compose exec fts_os-node \
../../../config/admin.pem \ ../../../config/admin.pem \
../../../config/admin-key.pem" ../../../config/admin-key.pem"
wait_for_bootstrapping
docker logs $fts_node docker logs $fts_node
printwc "$Green" "\n\nYou can now use: " if curl -sXGET "http://${INDEX_USER}:${OPNSREST}@localhost:9200"
printwc "$Cyan" "'http://${INDEX_USER}:${OPNSREST}@localhost:9200'\n" then
printwc "$Green" "\n\nYou can now use: "
printwc "$Cyan" "'http://${INDEX_USER}:${OPNSREST}@localhost:9200'\n"
else
printwc "$Red" "\n\nSetup have failed please report to: "
printwc "$Cyan" \
"'https://forge.switnet.net/switnet/simple-opensearch-installer'\n"
fi
} > >(tee -a opensearch-installer.log) 2> >(tee -a opensearch-installer.log >&2)