File: start

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, trixie
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (92 lines) | stat: -rwxr-xr-x 2,573 bytes parent folder | download | duplicates (2)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh

start_ts=$(date +%s)

PIDFILE="TMP_DIR/PORT/data/mysql_sandboxPORT.pid"
SOCKETFILE="TMP_DIR/PORT/mysql_sandboxPORT.sock"
BASEDIR="PERCONA_TOOLKIT_SANDBOX"

sandbox_is_alive() {
   # First, all these files must exist.
   [ -f $PIDFILE -a  -S $SOCKETFILE ] || return 1

   # And that PID file must have a PID.
   local pid=$(cat TMP_DIR/PORT/data/mysql_sandboxPORT.pid 2>/dev/null)
   [ "$pid" ] || return 1

   # Second, MySQL is truly alive when it respond to a ping.
   # It's not enough that the mysqld process is running because
   # InnoDB can take time to create ibdata1, etc.  So MySQL is
   # only alive when it responds to queries.
   $BASEDIR/bin/mysqladmin --defaults-file="TMP_DIR/PORT/my.sandbox.cnf" ping >/dev/null 2>&1
   [ $? -eq 0 ] || return 1
   echo "return 0"

   return 0
}

_seq() {
   local i="$1"
   awk "BEGIN { for(i=1; i<=$i; i++) print i; }"
}

# #############################################################################
# Script starts here
# #############################################################################

# If there's a PID or socket file, MySQL may already be alive.
if [ -f "$PIDFILE" -o -S "$SOCKETFILE" ]; then
   if sandbox_is_alive; then
      echo "MySQL test server on port PORT is running."
      exit 0
   fi

   # Sandbox exists but is not running.  Clear it and then start it.
   TMP_DIR/PORT/stop >/dev/null 2>&1
fi

echo -n "Starting MySQL test server on port PORT... "

# Start MySQL.
cwd=$PWD
cd $BASEDIR

encryption_plugins=""
plugins_dir_cmd=""

plugins_cmd=""
keyring_cmd=""

if [ -e "${BASEDIR}/lib/mysql/plugin/keyring_file.so" ]; then
     encryption_plugins="${BASEDIR}/lib/mysql/plugin/keyring_file.so"
fi

if [ ! -z "$encryption_plugins" ]; then
    plugins_cmd="--early-plugin-load=${encryption_plugins}"
    keyring_cmd="--keyring_file_data=/tmp/PORT/data/keyring"
    plugins_dir_cmd="--plugin-dir=${BASEDIR}/lib/mysql/plugin/"
fi

init_file="/tmp/PORT/mysql-init"
if [ -e $init_file ]; then
    $BASEDIR/bin/mysqld --defaults-file=/tmp/PORT/my.sandbox.cnf -u root --init-file $init_file $plugins_cmd $plugins_dir_cmd $keyring_cmd &
else
    $BASEDIR/bin/mysqld --defaults-file=/tmp/PORT/my.sandbox.cnf $plugins_cmd $plugins_dir_cmd $keyring_cmd > /dev/null 2>&1 &
fi
cd $PWD

# Wait for MySQL to actually be up, i.e. to respond to queries.
for i in $(_seq 60); do
   if sandbox_is_alive; then
      end_ts=$(date +%s)
      t=$((end_ts - start_ts))
      echo "OK (${t}s)"
      exit 0
   fi
   sleep 1
done

end_ts=$(date +%s)
t=$((end_ts - start_ts))
echo "FAILED (${t}s)"
exit 1