| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Scripts to run by MySQL systemd service |
| 4 | # |
| 5 | # Needed argument: pre |
| 6 | # |
| 7 | # pre mode : try to perform sanity check for configuration, log, data |
| 8 | |
| 9 | # Read a config option from mysql. Note that this will only work if a config |
| 10 | # file actually specifies the option, so it's important to specify a default |
| 11 | # $1 is application (e.g. mysqld for server) |
| 12 | # $2 is option |
| 13 | # $3 is default value used if no config value is found |
| 14 | get_mysql_option() { |
| 15 | result=$(my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1) |
| 16 | if [ -z "$result" ]; |
| 17 | then |
| 18 | result="$3" |
| 19 | fi |
| 20 | echo "$result" |
| 21 | } |
| 22 | sanity () { |
| 23 | if [ -e /etc/mysql/FROZEN -o -h /etc/mysql/FROZEN ]; then |
| 24 | echo "MySQL has been frozen to prevent damage to your system. Please see /etc/mysql/FROZEN for help." |
| 25 | exit 1 |
| 26 | fi |
| 27 | if [ ! -r /etc/mysql/my.cnf ]; then |
| 28 | echo "MySQL configuration not found at /etc/mysql/my.cnf. Please create one." |
| 29 | exit 1 |
| 30 | fi |
| 31 | datadir=$(get_mysql_option mysqld datadir "/var/lib/mysql") |
| 32 | if [ ! -d "${datadir}" ] && [ ! -L "${datadir}" ]; then |
| 33 | echo "MySQL data dir not found at ${datadir}. Please create one." |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | if [ ! -d "${datadir}/mysql" ] && [ ! -L "${datadir}/mysql" ]; then |
| 38 | echo "MySQL system database not found in ${datadir}. Please run mysqld --initialize." |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | # Do a test start to make sure there are no configuration issues or similar |
| 43 | # mysqld --verbose --help will output a full listing of settings and plugins. |
| 44 | # To do so it needs to initialize the database, so it can be used as a test |
| 45 | # for whether or not the server can start. We redirect stdout to /dev/null so |
| 46 | # only the error messages are left. |
| 47 | result=0 |
| 48 | output=$(mysqld --verbose --help --innodb-read-only 2>&1 > /dev/null) || result=$? |
| 49 | if [ ! "$result" = "0" ]; then |
| 50 | echo "ERROR: Unable to start MySQL server:" >&2 |
| 51 | echo "$output" >&2 |
| 52 | echo "Please take a look at https://wiki.debian.org/Teams/MySQL/FAQ for tips on fixing common upgrade issues." >&2 |
| 53 | echo "Once the problem is resolved, restart the service." >&2 |
| 54 | exit 1 |
| 55 | fi |
| 56 | } |
| 57 | |
| 58 | case $1 in |
| 59 | "pre") sanity ;; |
| 60 | esac |