diff options
Diffstat (limited to 'debian/smf/mysql')
-rwxr-xr-x | debian/smf/mysql | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/debian/smf/mysql b/debian/smf/mysql new file mode 100755 index 0000000..ba7cefd --- /dev/null +++ b/debian/smf/mysql @@ -0,0 +1,76 @@ +#!/bin/bash + +MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf" + +export HOME=/etc/mysql +cd / +umask 077 + +mysqld_get_param() { + /usr/sbin/mysqld --print-defaults \ + | tr " " "\n" \ + | grep -- "--$1" \ + | tail -n 1 \ + | cut -d= -f2 +} + +## Checks if there is a server running and if so if it is accessible. +# +# check_alive insists on a pingable server +# check_dead also fails if there is a lost mysqld in the process list +# +# Usage: boolean mysqld_status [check_alive|check_dead] [warn|nowarn] +mysqld_status () { + ping_output=`$MYADMIN ping 2>&1`; ping_alive=$(( ! $? )) + + ps_alive=0 + pidfile=`mysqld_get_param pid-file` + if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; 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 # EXIT_SUCCESS + else + if [ "$2" = "warn" ]; then + echo -e "$ps_alive processes alive and '$MYADMIN ping' resulted in\n$ping_output\n" | $ERR_LOGGER -p daemon.debug + fi + return 1 # EXIT_FAILURE + fi +} + +start() { + test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld + /usr/bin/mysqld_safe > /dev/null 2>&1 & + for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do + sleep 1 + if mysqld_status check_alive nowarn ; then break; fi + done + if mysqld_status check_alive warn; then + output=$(/etc/mysql/debian-start) + [ -n "$output" ] && echo "$output" + else + echo "Please take a look at the syslog" + fi +} + +stop() { + shutdown_out=`$MYADMIN shutdown 2>&1`; r=$? + if [ "$r" -ne 0 ]; then + echo "mysqld shutdown failed: $shutdown_out" + echo "killing by signal" + pidfile=`mysqld_get_param pid-file` + if [ -f "$pidfile" ]; then + pkill mysqld + fi + fi +} + +refresh() { + $MYADMIN reload +} + +case "$1" in + start) start;; + stop) stop;; + refresh) refresh;; +esac |