1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-08 14:22:09 +03:00

chore(install): no more deps for awk and ps for postinstall script

This commit is contained in:
Leonid Fedorov
2025-06-10 10:58:06 +00:00
committed by drrtuy
parent 78de8799ba
commit a0c861adbb

View File

@@ -5,11 +5,76 @@
# Post-install steps for columnstore install
running_systemd() {
if [ "$(ps --no-headers -o comm 1)" = "systemd" ]; then
# Check if init process (PID 1) is systemd by reading /proc/1/comm
if [ -r "/proc/1/comm" ]; then
if [ "$(cat /proc/1/comm)" = "systemd" ]; then
echo 0
else
echo 1
return 0
fi
fi
# Alternative check using /proc/1/exe symlink
if [ -L "/proc/1/exe" ]; then
local exe_target
exe_target=$(readlink -f "/proc/1/exe")
if [[ "${exe_target##*/}" == "systemd" ]]; then
echo 0
return 0
fi
fi
# Fallback check for systemd presence in /run/systemd
if [ -d "/run/systemd/system" ]; then
echo 0
return 0
fi
echo 1
return 1
}
get_parent_pid() {
local pid=$1
local ppid
# Read the stat file for the given PID
if [ -f "/proc/$pid/stat" ]; then
# Read the entire stat file into a variable
read -r stat <"/proc/$pid/stat"
# Split into array (parent PID is the 4th field)
IFS=' ' read -ra stat_array <<<"$stat"
# The PPID is the 4th element (0-based index 3)
ppid=${stat_array[3]}
echo "$ppid"
return 0
else
echo "Error: Process $pid does not exist" >&2
return 1
fi
}
get_env_var_value() {
local pid=$1
local var_name=$2
local env_file="/proc/$pid/environ"
if [ ! -r "$env_file" ]; then
echo "Error: Cannot read $env_file" >&2
return 1
fi
# Read null-delimited environ file and process each line
while IFS= read -r -d '' line; do
if [[ "$line" == "${var_name}="* ]]; then
echo "${line#*=}"
return 0
fi
done <"$env_file"
return 1
}
# This function recursively(up to PID 1) searches for
@@ -19,13 +84,12 @@ find_env_var() {
pid=$$
ENV_VAR=''
while [ -z "$ENV_VAR" -a "$pid" != 1 ]; do
ppid=$(ps -oppid -p$pid|tail -1|awk '{print $1}')
ppid=$(get_parent_pid $pid)
# This condition is true in containers
if [ "$ppid" == 0 ]; then
break;
break
fi
env=$(strings /proc/$ppid/environ)
ENV_VAR=$(echo "$env"|awk -F= "\$1 == \"$env_var_name\" { print \$2; }")
ENV_VAR=$(get_env_var_value $ppid $env_var_name)
pid=$ppid
done
echo $ENV_VAR
@@ -39,13 +103,13 @@ fi
checkForError() {
# check for password error
grep "ERROR 1045" ${installLogDir}/mysql_install.log > ${installLogDir}/error.check
if [ `cat ${installLogDir}/error.check | wc -c` -ne 0 ]; then
grep "ERROR 1045" ${installLogDir}/mysql_install.log >${installLogDir}/error.check
if [ $(cat ${installLogDir}/error.check | wc -c) -ne 0 ]; then
echo "There were authentication issues running install_mcs_mysql.sh \
script. The log is available in ${installLogDir}/mysql_install.log. Please re-run \
columnstore-post-install manually after solving the authentication issues."
rm -f ${installLogDir}/error.check
return 2;
return 2
fi
rm -f ${installLogDir}/error.check
@@ -54,7 +118,7 @@ columnstore-post-install manually after solving the authentication issues."
# See if engine columnstore exist
#---------------------------------------------------------------------------
echo "checking for engine columnstore..."
$MDB --execute="show engines" 2> ${installLogDir}/post-mysql-install.log | grep -i columnstore >> ${installLogDir}/post-mysql-install.log 2>&1
$MDB --execute="show engines" 2>${installLogDir}/post-mysql-install.log | grep -i columnstore >>${installLogDir}/post-mysql-install.log 2>&1
#
# Add compressiontype column to SYSCOLUMN if applicable
@@ -66,19 +130,19 @@ columnstore-post-install manually after solving the authentication issues."
echo "columnstore exists"
return 0;
return 0
}
rpmmode=install
user=`whoami 2>/dev/null`
user=$(whoami 2>/dev/null)
quiet=0
stop_mysqld=0
if [ -z "$(pgrep -x mariadbd)" ];then
if [ -z "$(pgrep -x mariadbd)" ]; then
# Startup mysqld
systemctl cat mariadb.service > /dev/null 2>&1
systemctl cat mariadb.service >/dev/null 2>&1
if [ $? -eq 0 ] && [ $(running_systemd) -eq 0 ]; then
systemctl start mariadb.service
else
@@ -107,12 +171,11 @@ if [ -f @ENGINE_SYSCONFDIR@/columnstore/Columnstore.xml.rpmsave ]; then
fi
touch /dev/shm/columnstore-test && rm /dev/shm/columnstore-test
if [ $? -ne 0 ] ; then
if [ $? -ne 0 ]; then
echo "User $user will need R/W access to /dev/shm."
exit 1
fi
profileFile="/etc/profile.d/columnstoreAlias.sh"
/bin/cp -f @ENGINE_SUPPORTDIR@/columnstoreAlias /etc/profile.d/columnstoreAlias.sh
chmod 644 /etc/profile.d/columnstoreAlias.sh >/dev/null 2>&1
@@ -124,7 +187,7 @@ test -d @ENGINE_LOGDIR@/trace || mkdir @ENGINE_LOGDIR@/trace >/dev/null 2>&1
test -d @ENGINE_LOGDIR@/cpimport || mkdir @ENGINE_LOGDIR@/cpimport >/dev/null 2>&1
test -d @ENGINE_LOGDIR@/install || mkdir @ENGINE_LOGDIR@/install >/dev/null 2>&1
test -h @ENGINE_LOGDIR@/data && rm -f @ENGINE_LOGDIR@/data
chmod 755 @ENGINE_LOGDIR@/corefiles > /dev/null 2>&1
chmod 755 @ENGINE_LOGDIR@/corefiles >/dev/null 2>&1
chmod 777 @ENGINE_LOGDIR@/cpimport
chmod 777 @ENGINE_LOGDIR@/install
installLogDir=@ENGINE_LOGDIR@/install
@@ -136,7 +199,7 @@ test -d @ENGINE_DATADIR@/data1/systemFiles/dataTransaction || rmdir @ENGINE_DATA
test -d @ENGINE_DATADIR@/data1/systemFiles/dataTransaction/archive || rmdir @ENGINE_DATADIR@/data1/systemFiles/dataTransaction/archive >/dev/null 2>&1
chmod 1755 @ENGINE_DATADIR@/data1 >/dev/null 2>&1
chmod -R 1755 @ENGINE_DATADIR@/data1/systemFiles >/dev/null 2>&1
chmod 1755 @ENGINE_SYSCONFDIR@/columnstore > /dev/null 2>&1
chmod 1755 @ENGINE_SYSCONFDIR@/columnstore >/dev/null 2>&1
#create the bulk-load dirs
mkdir -p @ENGINE_LOGDIR@/data/bulk/data/import >/dev/null 2>&1
@@ -147,22 +210,22 @@ rm -f @ENGINE_LOGDIR@/data/bulk/tmpjob/* >/dev/null 2>&1
chmod -R 777 @ENGINE_LOGDIR@/data
#get columnstore temp file directory name
tmpDir=`@ENGINE_BINDIR@/mcsGetConfig SystemConfig SystemTempFileDir`
scratchDir=$tmpDir`@ENGINE_BINDIR@/mcsGetConfig SystemConfig hdfsRdwrScratch`
tmpDir=$(@ENGINE_BINDIR@/mcsGetConfig SystemConfig SystemTempFileDir)
scratchDir=$tmpDir$(@ENGINE_BINDIR@/mcsGetConfig SystemConfig hdfsRdwrScratch)
mkdir $tmpDir >/dev/null 2>&1
mkdir $scratchDir >/dev/null 2>&1
chmod 777 $tmpDir
chmod 777 $scratchDir
#create mount directories
mkdir /mnt/tmp > /dev/null 2>&1
mkdir /mnt/tmp >/dev/null 2>&1
if [ $user = "root" ]; then
#setup the columnstore service script
rm -f /etc/init.d/columnstore >/dev/null 2>&1
rm -f /etc/default/columnstore
systemctl=`which systemctl 2>/dev/null`
systemctl=$(which systemctl 2>/dev/null)
if [ -n "$systemctl" ]; then
# Removing a separate ExeMgr unit.
if [[ -f /usr/lib/systemd/system/mcs-exemgr.service ]]; then
@@ -190,27 +253,27 @@ if [ $user = "root" ]; then
cp @ENGINE_SUPPORTDIR@/mcs-storagemanager.service /usr/lib/systemd/system/. >/dev/null 2>&1
cp @ENGINE_SUPPORTDIR@/mcs-storagemanager.service /lib/systemd/system/. >/dev/null 2>&1
systemctl enable mariadb-columnstore >/dev/null 2>&1
systemctl enable mcs-controllernode > /dev/null 2>&1
systemctl enable mcs-ddlproc > /dev/null 2>&1
systemctl enable mcs-dmlproc > /dev/null 2>&1
systemctl enable mcs-primproc > /dev/null 2>&1
systemctl enable mcs-workernode@1 > /dev/null 2>&1
systemctl enable mcs-writeengineserver > /dev/null 2>&1
systemctl enable mcs-loadbrm > /dev/null 2>&1
systemctl enable mcs-storagemanager > /dev/null 2>&1
systemctl enable mcs-controllernode >/dev/null 2>&1
systemctl enable mcs-ddlproc >/dev/null 2>&1
systemctl enable mcs-dmlproc >/dev/null 2>&1
systemctl enable mcs-primproc >/dev/null 2>&1
systemctl enable mcs-workernode@1 >/dev/null 2>&1
systemctl enable mcs-writeengineserver >/dev/null 2>&1
systemctl enable mcs-loadbrm >/dev/null 2>&1
systemctl enable mcs-storagemanager >/dev/null 2>&1
else
chkconfig=`which chkconfig 2>/dev/null`
chkconfig=$(which chkconfig 2>/dev/null)
if [ -n "$chkconfig" ]; then
cp @ENGINE_SBINDIR@/columnstore /etc/init.d/. >/dev/null 2>&1
chkconfig --add columnstore > /dev/null 2>&1
chkconfig columnstore on > /dev/null 2>&1
chkconfig --add columnstore >/dev/null 2>&1
chkconfig columnstore on >/dev/null 2>&1
else
cp @ENGINE_SBINDIR@/columnstore /etc/init.d/. >/dev/null 2>&1
updaterc=`which update-rc.d 2>/dev/null`
updaterc=$(which update-rc.d 2>/dev/null)
if [ -n "$updaterc" ]; then
update-rc.d columnstore defaults 99 > /dev/null 2>&1
update-rc.d columnstore defaults 99 >/dev/null 2>&1
else
echo ""
echo "Package 'systemctl', 'chkconfig' or 'update-rc.d' not installed, contact your sysadmin if you want to setup to autostart for columnstore"
@@ -226,7 +289,7 @@ if [ -f @MARIADB_MYCNFDIR@/columnstore.cnf.rpmsave ]; then
fi
if [ $user = "root" ]; then
@ENGINE_BINDIR@/columnstoreSyslogSetup.sh install > $installLogDir/syslog_install.log 2>&1
@ENGINE_BINDIR@/columnstoreSyslogSetup.sh install >$installLogDir/syslog_install.log 2>&1
#check if MariaDB Columnstore system logging was setup
cat $installLogDir/syslog_install.log | grep 'No System Logging' >/dev/null 2>&1
@@ -236,7 +299,7 @@ if [ $user = "root" ]; then
else
chown $user:$user @ENGINE_SYSCONFDIR@/columnstore/Columnstore.xml
cat <<EOD
cat <<EOD
NOTE: For non-root install, you will need to run the following commands as root user to
setup the MariaDB ColumnStore System Logging
@@ -262,12 +325,12 @@ rm -f $lockdir/columnstore
@ENGINE_SBINDIR@/install_mcs_mysql.sh --tmpdir=$installLogDir
# Restart MDB to enable plugin
systemctl cat mariadb.service > /dev/null 2>&1
systemctl cat mariadb.service >/dev/null 2>&1
if [ $? -eq 0 ] && [ $(running_systemd) -eq 0 ]; then
systemctl restart mariadb.service > /dev/null 2>&1
systemctl restart mariadb.service >/dev/null 2>&1
else
pkill mysqld > /dev/null 2>&1
while [ -n "$(pgrep -x mysqld)" ] ; do
pkill mysqld >/dev/null 2>&1
while [ -n "$(pgrep -x mysqld)" ]; do
sleep 1
done
/usr/bin/mysqld_safe &
@@ -375,7 +438,7 @@ fi
if [ $(running_systemd) -eq 0 ]; then
chown -R @DEFAULT_USER@:@DEFAULT_GROUP@ @ENGINE_LOGDIR@
chown -R @DEFAULT_USER@:@DEFAULT_GROUP@ /etc/columnstore
findcmd=`which find 2>/dev/null`
findcmd=$(which find 2>/dev/null)
if [ -n "$findcmd" ]; then
if [[ $($findcmd @ENGINE_DATADIR@ -maxdepth 3 ! -user @DEFAULT_USER@ -exec echo {} \; -quit 2>/dev/null) ]]; then
echo "At least one file is not owned by @DEFAULT_USER@ in @ENGINE_DATADIR@. Running chown..."
@@ -390,7 +453,7 @@ if [ $(running_systemd) -eq 0 ]; then
chmod 777 /dev/shm
fi
systemctl cat mariadb-columnstore.service > /dev/null 2>&1
systemctl cat mariadb-columnstore.service >/dev/null 2>&1
if [ $? -eq 0 ] && [ $(running_systemd) -eq 0 ]; then
# mask mariadb-columnstore service to prevent starting services and dbbuilder
@@ -421,13 +484,13 @@ if [ $? -eq 0 ] && [ $(running_systemd) -eq 0 ]; then
flock -u "$fd_lock"
fi
if [ $stop_mysqld -eq 1 ];then
if [ $stop_mysqld -eq 1 ]; then
# Make sure we stop mariadb since it wasn't running prior to columnstore installation
systemctl cat mariadb.service > /dev/null 2>&1
systemctl cat mariadb.service >/dev/null 2>&1
if [ $? -eq 0 ] && [ $(running_systemd) -eq 0 ]; then
systemctl stop mariadb.service > /dev/null 2>&1
systemctl stop mariadb.service >/dev/null 2>&1
else
pkill mysqld > /dev/null 2>&1
pkill mysqld >/dev/null 2>&1
fi
fi