#!/bin/sh #---------------------------------------------------------------------------- # /usr/lib/systemd/scripts/mysql-common-mariadb-start - MariaDB Server start post # # Creation: 2023-10-03 hbfl # Last Update: $Id: mysql-common-tools-connections 106681 2023-10-03 17:22:25Z hbfl # # Copyright (c) 2014-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # --------------------------------------------------------------------------- # defaults # --------------------------------------------------------------------------- get_defaults() { # default values . /srv/mysql/defaults.info } # --------------------------------------------------------------------------- # check status of MariaDB/MySQL Database # --------------------------------------------------------------------------- check_status() { if [ -f ${mysql_pid_file} ] then exit 1 fi } # --------------------------------------------------------------------------- # check status of MariaDB/MySQL Database # --------------------------------------------------------------------------- sanity_checks() { ERR_LOGGER="logger -p daemon.err -t /usr/lib/systemd/system/${package_name}.service -i" . /etc/config.d/${package_name} # check for buggy options if /usr/bin/grep -q ^expire.logs.days /etc/mysql/my${my_path}.cnf && ! /usr/bin/grep -q ^log.bin /etc/mysql/my${my_path}.cnf then echo "ERROR: Using expire_logs_days without log_bin crashes the server." | $ERR_LOGGER exit 1 fi # check for diskspace shortage if LC_ALL=C BLOCKSIZE= /usr/bin/df --portability "${mysql_datadir:-/srv/mysql/${my_path}}" | /usr/bin/tail -n 1 | /usr/bin/awk '{ exit ($4>4096) }' then echo "ERROR: The partition with "${mysql_datadir:-/srv/mysql/${my_path}}" is too full!" | $ERR_LOGGER exit 1 fi } # --------------------------------------------------------------------------- # wait if create/remove pid files # --------------------------------------------------------------------------- wait_for_pid() { for COUNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 do case "$1" in 'created') test -s ${mysql_pid_file} && break ;; 'removed') test ! -s ${mysql_pid_file} && break ;; esac sleep 1 # echo -n '.' done } # --------------------------------------------------------------------------- # start mariadb # --------------------------------------------------------------------------- start_mariadb() { if [ -f /etc/sysconfig/${package_name} ] then . /etc/sysconfig/${package_name} fi /usr/lib/mysql/${my_path}/bin/${db_mysqld} --defaults-file=/etc/mysql/my${my_path}.cnf --user=mysql $MYSQL_OPTION & wait_for_pid 'created' } # --------------------------------------------------------------------------- # check status of MariaDB/MySQL Database # --------------------------------------------------------------------------- set_default_sock() { if [ ${mysql_port:-0} = 3306 ] then cd /run/mysql /usr/bin/ln -sf ${my_path}/mysql.sock fi } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- main() { package_name="${1}" project_name=$(echo "${package_name}" | tr [:lower:] [:upper:]) my_path=$(echo "${package_name}" | sed 's|[^[:digit:]]||g') get_defaults check_status sanity_checks start_mariadb set_default_sock exit 0 } # --------------------------------------------------------------------------- # call function main # --------------------------------------------------------------------------- main "${@}" # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------