2
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
3
# This file is public domain and comes with NO WARRANTY of any kind
5
# Mysql daemon start/stop script. Multi-instance enhancements by Tim Bunce.
7
# Usually this is put in /etc/init.d (at least on machines SYSV R4
8
# based systems) and linked to
9
# /etc/rc3.d/S99mysql.svr1
10
# and /etc/rc0.d/S01mysql.svr1
11
# When this is done the mysql server will be started when the machine is
12
# started and shut down when the systems goes down. The '.svr1' suffix can
13
# be used to identify one of a number of servers. Multiple symlinks can be
14
# created, one per instance. The 'svrN' suffix can then be used to
15
# prefix configuration variables in a seperate section of /etc/my.cnf.
18
# A typical multi-instance /etc/my.cnf file would look like:
21
# set-variable = key_buffer_size=16M
22
# set-variable = max_allowed_packet=1M
23
# [mysql_multi_server]
24
# svr1-datadir=/foo1/bar
25
# svr2-datadir=/foo2/bar
27
# and then the /foo1/bar/my.cnf and /foo2/bar/my.cnf files
28
# would contain all the *instance specific* configurations.
30
# This script can also be run manually in which case the server instance
31
# is identified by an extra argument, for example:
32
# /etc/init.d/mysql stop svr3
35
PATH=/sbin:/usr/sbin:/bin:/usr/bin
38
mode=$1 # start or stop
39
svr=$2 # eg 'svr1' (optional)
41
then name=`basename $0`
45
# Extract identity of the server we are working with
46
svr=`echo "$name" | sed -e 's/.*\<\(svr[1-9][0-9]*\)\>.*/\1/'`
49
echo "Can't determine database svr number from name '$name'"
53
echo "mysqld $svr $mode"
58
--basedir=*|--${svr}-basedir=*)
59
basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
60
--datadir=*|--${svr}-basedir=*)
61
datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
62
--pid-file=*|--${svr}-basedir=*)
63
pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
68
# Get arguments from the my.cnf file, groups [mysqld], [mysql_server],
69
# and mysql_multi_server
70
if test -x ./bin/my_print_defaults
72
print_defaults="./bin/my_print_defaults"
73
elif test -x @bindir@/my_print_defaults
75
print_defaults="@bindir@/my_print_defaults"
76
elif test -x @bindir@/mysql_print_defaults
78
print_defaults="@bindir@/mysql_print_defaults"
80
# Try to find basedir in /etc/my.cnf
85
subpat='^[^=]*basedir[^=]*=\(.*\)$'
86
dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf
89
d=`echo $d | sed -e 's/[ ]//g'`
90
if test -x "$d/bin/my_print_defaults"
92
print_defaults="$d/bin/my_print_defaults"
95
if test -x "$d/bin/mysql_print_defaults"
97
print_defaults="$d/bin/mysql_print_defaults"
103
# Hope it's in the PATH ... but I doubt it
104
test -z "$print_defaults" && print_defaults="my_print_defaults"
107
datadir=@localstatedir@
110
parse_arguments `$print_defaults $defaults mysqld mysql_server mysql_multi_server`
112
if test -z "$basedir"
117
bindir="$basedir/bin"
119
if test -z "$pid_file"
121
pid_file=$datadir/`@HOSTNAME@`.pid
125
* ) pid_file="$datadir/$pid_file" ;;
129
# Safeguard (relative paths, core dumps..)
136
if test -x $bindir/mysqld_safe
138
# We only need to specify datadir and pid-file here and we
139
# get all other instance-specific config from $datadir/my.cnf.
140
# We have to explicitly pass --defaults-extra-file because it
141
# reads the config files before the command line options.
142
# Also it must be first because of the way mysqld_safe works.
143
$bindir/mysqld_safe --defaults-extra-file=$datadir/my.cnf \
144
--datadir=$datadir --pid-file=$pid_file &
145
# Make lock for RedHat / SuSE
146
if test -d /var/lock/subsys
148
touch /var/lock/subsys/mysql
151
echo "Can't execute $bindir/mysqld_safe"
156
# Stop daemon. We use a signal here to avoid having to know the
158
if test -f "$pid_file"
160
mysqld_pid=`cat $pid_file`
161
echo "Killing mysqld $svr with pid $mysqld_pid"
163
# mysqld should remove the pid_file when it exits, so wait for it.
166
while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ]
168
[ -z "$flags" ] && echo "Wait for mysqld $svr to exit\c" || echo ".\c"
173
then echo " gave up waiting!"
177
# delete lock for RedHat / SuSE
178
if test -e /var/lock/subsys/mysql
180
rm /var/lock/subsys/mysql
183
echo "No mysqld pid file found. Looked for $pid_file."
189
echo "usage: $0 start|stop [ svrN ]"