mirror of https://github.com/sipwise/ngcpcfg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.3 KiB
69 lines
1.3 KiB
#!/bin/bash
|
|
|
|
if [ $# -gt 0 ] ; then
|
|
COUNT=$1
|
|
MYSQLID="$2"
|
|
else
|
|
COUNT=60
|
|
fi
|
|
|
|
if [ "$MYSQLID" = "2" ] ; then
|
|
# [client2] on /etc/mysql/debian.cnf
|
|
SUFF="2"
|
|
fi
|
|
|
|
if [ $COUNT -le 0 ] ; then
|
|
echo "Usage: $0 <number_of_seconds> [<mysqlid>]" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! [ -x /usr/sbin/mysqld ] || ! [ -x /usr/bin/mysqladmin ] ; then
|
|
echo "Error: mysqld or mysqladmin not present. Exiting." >&2
|
|
exit 1
|
|
fi
|
|
|
|
mysqld_get_param() {
|
|
/usr/sbin/mysqld --defaults-group-suffix=$SUFF --print-defaults 2>/dev/null \
|
|
| tr " " "\n" \
|
|
| grep -- "--$1" \
|
|
| tail -n 1 \
|
|
| cut -d= -f2
|
|
}
|
|
|
|
mysqld_status () {
|
|
if /usr/bin/mysqladmin --defaults-group-suffix=$SUFF \
|
|
--defaults-file=/etc/mysql/debian.cnf ping 2>&1 ; then
|
|
ping_alive=1
|
|
else
|
|
ping_alive=0
|
|
fi
|
|
|
|
ps_alive=0
|
|
pidfile=$(mysqld_get_param pid-file)
|
|
|
|
if [ -f "$pidfile" ] && ps "$(cat "$pidfile")" &>/dev/null ; then
|
|
ps_alive=1
|
|
fi
|
|
|
|
if [ "$1" = "check_alive" -a $ping_alive = 1 ] ||
|
|
[ "$1" = "check_dead" -a $ping_alive = 0 -a $ps_alive = 0 ]; then
|
|
return 0
|
|
fi
|
|
|
|
return 1
|
|
}
|
|
|
|
printf "Checking MySQL service status (for a maximum of %s seconds): " "$COUNT"
|
|
for _ in $(seq 1 $COUNT) ; do
|
|
if mysqld_status check_alive warn; then
|
|
printf "available.\n"
|
|
exit 0
|
|
else
|
|
printf "."
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
printf "still not available, giving up.\n"
|
|
exit 1
|