2017-11-24 23:09:30

How to run a database in %check section of RPM spec file

Sometimes I get the question: How to run a database in %check section of RPM spec file.

Coincidentaly, I just stumbled upon this nice example from qlpi package:

%check
# Running a MariaDB server
MYSQL_TEST_HOST=127.0.0.1
MYSQL_TEST_PORT=3308
MYSQL_TEST_SOCKET=$PWD/mysql.sock
MYSQL_PID_FILE=$PWD/mysql.pid

rm -rf data
mkdir  data
# Create the Database
%{_bindir}/mysql_install_db \
  --log-error=$PWD/mysql.log \
  --datadir=$PWD/data

# Launch the Server
%{_libexecdir}/mysqld \
   --socket=$MYSQL_TEST_SOCKET \
   --log-error=$PWD/mysql.log \
   --pid-file=$MYSQL_PID_FILE \
   --port=$MYSQL_TEST_PORT \
   --datadir=$PWD/data &

n=15
while [ $n -gt 0 ]; do
  RESPONSE=$(%{_bindir}/mysqladmin --no-defaults --socket="$MYSQL_TEST_SOCKET" --user=root ping 2>&1 || :)
  if [ "$RESPONSE" == "mysqld is alive" ]; then
    break
  fi
  n=$(expr $n - 1)
  sleep 1
done

#Do some tests here

# Cleanup
if [ -s $MYSQL_PID_FILE ]; then
  kill $(cat $MYSQL_PID_FILE)
fi
kill $PHPPID || :

Similary for Redis:

%check
REDIS_PORT=7777
redis-server --port $REDIS_PORT &
# do some testing here
redis-cli -p $REDIS_PORT shutdown

Posted by Miroslav Suchý | Permanent link
Comments
comments powered by Disqus