File: mysql-server.init

package info (click to toggle)
mysql 3.23.49-8.13
  • links: PTS
  • area: main
  • in suites: woody
  • size: 65,624 kB
  • ctags: 45,242
  • sloc: ansic: 255,722; cpp: 86,801; perl: 26,117; tcl: 19,882; sh: 18,775; asm: 4,001; yacc: 2,626; makefile: 2,494; java: 2,300; awk: 1,484; sed: 428
file content (98 lines) | stat: -rw-r--r-- 2,135 bytes parent folder | download
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
93
94
95
96
97
98
#!/bin/sh -e
#
# MySQL daemon start/stop script.
#
# Debian version. Based on the original by TcX.
#

test $DEBIAN_SCRIPT_DEBUG && set -v -x 

test -x /usr/sbin/mysqld || exit 0

SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
CONF=/etc/mysql/my.cnf
MYADMIN="/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf"

# Safeguard (relative paths, core dumps..)
cd /
umask 077
export PATH=/bin:/usr/bin

# mysqladmin likes to read /root/.my.cnf. This is usually not what I want
# as many admins e.g. only store a password without a username there and
# so break my scripts.
export HOME=/etc/mysql/

is_mysqld_alive () {
    if [ -n "`$MYADMIN ping 2>/dev/null`" ]; then return 0; else return 1; fi
}

case "$1" in
  'start')
	# Start daemon
	echo -n "Starting MySQL database server: mysqld"	
	/usr/bin/safe_mysqld > /dev/null 2>&1 &
	for i in 1 2 3 4 5 6; do
	  if is_mysqld_alive; then break; fi
          sleep 1
        done
	if is_mysqld_alive; then
          echo "."
	else
	  echo "...failed."
	fi
	;;

  'stop')
	# * As a passwordless mysqladmin (e.g. via ~/.my.cnf) must be possible
	# at least for cron, we can rely on it here, too. (although we have 
	# to specify it explicit as e.g. sudo environments points to the normal
	# users home and not /root)
	echo -n "Stopping MySQL database server: mysqld"	
	if is_mysqld_alive; then
	  set +e
	  $MYADMIN shutdown
	  r=$?
	  set -e
	  if [ "$r" -ne 0 ]; then
	    echo "...failed"
	    echo -n "Killing MySQL database server by signal: mysqld"
            for i in 1 2 3 4 5 6; do
	      killall -15 mysqld
              sleep 1
	      killall -9 mysqld
              if is_mysqld_alive; then break; fi
            done
	  fi
        fi

        if is_mysqld_alive; then
	  echo "...failed."
	  echo "Please stop the daemon yourself!"
	  exit -1
	else
	  echo "."
        fi
	;;

  'restart')
	set +e; $SELF stop; set -e
	$SELF start 
	;;

  'reload'|'force-reload')
  	echo -n "Reloading MySQL database server: mysqld"
	$MYADMIN reload
	echo "."
	;;

  'status')
	$MYADMIN version
  	;;

  *)
	echo "Usage: $SELF start|stop|restart|reload|force-reload"
	exit 1
	;;
esac