2
2
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
3
3
# This file is public domain and comes with NO WARRANTY of any kind
5
# Script to start the Drizzle daemon and restart it if it dies unexpectedly
5
# Script to start the MySQL daemon and restart it if it dies unexpectedly
7
# This should be executed in the Drizzle base directory if you are using a
7
# This should be executed in the MySQL base directory if you are using a
8
8
# binary installation that is not installed in its compile-time default
11
11
# mysql.server works by first doing a cd to the base directory and from there
12
# executing drizzled_safe
12
# executing mysqld_safe
17
17
# Initial logging status: error log is not open, and not using syslog
26
exec_prefix=@exec_prefix@
29
includedir=@includedir@
32
syslog_tag_drizzled=drizzled
33
syslog_tag_drizzled_safe=drizzled_safe
25
syslog_tag_mysqld=mysqld
26
syslog_tag_mysqld_safe=mysqld_safe
35
28
trap '' 1 2 3 15 # we shouldn't let anyone kill us
49
42
--no-defaults Don't read the system defaults file
50
43
--defaults-file=FILE Use the specified defaults file
51
44
--defaults-extra-file=FILE Also use defaults from the specified file
45
--ledir=DIRECTORY Look for mysqld in the specified directory
52
46
--open-files-limit=LIMIT Limit the number of open files
53
47
--core-file-size=LIMIT Limit core files to the specified size
54
48
--timezone=TZ Set the system timezone
55
--drizzled=FILE Use the specified file as drizzled
56
--drizzled-version=VERSION Use "drizzled-VERSION" as drizzled
57
--nice=NICE Set the scheduling priority of drizzled
58
--skip-kill-drizzled Don't try to kill stray drizzled processes
49
--mysqld=FILE Use the specified file as mysqld
50
--mysqld-version=VERSION Use "mysqld-VERSION" as mysqld
51
--nice=NICE Set the scheduling priority of mysqld
52
--skip-kill-mysqld Don't try to kill stray mysqld processes
59
53
--syslog Log messages to syslog with 'logger'
60
54
--skip-syslog Log messages to error log (default)
61
--syslog-tag=TAG Pass -t "drizzled-TAG" to 'logger'
55
--syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger'
63
All other options are passed to the drizzled program.
57
All other options are passed to the mysqld program.
98
msg="`date +'%y%m%d %H:%M:%S'` drizzled_safe $*"
92
msg="`date +'%y%m%d %H:%M:%S'` mysqld_safe $*"
101
95
init) ;; # Just echo the message, don't save it anywhere
102
96
file) echo "$msg" >> "$err_log" ;;
103
syslog) logger -t "$syslog_tag_drizzled_safe" -p "$priority" "$*" ;;
97
syslog) logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;;
105
99
echo "Internal program error (non-fatal):" \
106
100
" unknown logging method '$logging'" >&2
122
116
file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;;
124
# drizzled often prefixes its messages with a timestamp, which is
118
# mysqld often prefixes its messages with a timestamp, which is
125
119
# redundant when logging to syslog (which adds its own timestamp)
126
120
# However, we don't strip the timestamp with sed here, because
127
121
# sed buffers output (only GNU sed supports a -u (unbuffered) option)
128
122
# which means that messages may not get sent to syslog until the
129
# drizzled process quits.
130
cmd="$cmd 2>&1 | logger -t '$syslog_tag_drizzled' -p daemon.error"
123
# mysqld process quits.
124
cmd="$cmd 2>&1 | logger -t '$syslog_tag_mysqld' -p daemon.error"
133
127
echo "Internal program error (non-fatal):" \
160
154
val=`echo "$arg" | sed -e "s;--[^=]*=;;"`
162
# these get passed explicitly to drizzled
156
# these get passed explicitly to mysqld
163
157
--basedir=*) MY_BASEDIR_VERSION="$val" ;;
164
158
--datadir=*) DATADIR="$val" ;;
165
159
--pid-file=*) pid_file="$val" ;;
166
160
--user=*) user="$val"; SET_USER=1 ;;
168
# these might have been set in a [drizzled_safe] section of my.cnf
169
# they are added to drizzled command line to override settings from my.cnf
162
# these might have been set in a [mysqld_safe] section of my.cnf
163
# they are added to mysqld command line to override settings from my.cnf
170
164
--log-error=*) err_log="$val" ;;
171
165
--port=*) mysql_tcp_port="$val" ;;
172
166
--socket=*) mysql_unix_port="$val" ;;
174
# drizzled_safe-specific options - must be set in my.cnf ([drizzled_safe])!
168
# mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
175
169
--core-file-size=*) core_file_size="$val" ;;
176
--drizzled=*) DRIZZLED="$val" ;;
177
--drizzled-version=*)
170
--ledir=*) ledir="$val" ;;
171
--mysqld=*) MYSQLD="$val" ;;
178
173
if test -n "$val"
180
DRIZZLED="drizzled-$val"
185
180
--nice=*) niceness="$val" ;;
186
181
--open-files-limit=*) open_files="$val" ;;
187
--skip-kill-drizzled*) KILL_DRIZZLED=0 ;;
182
--skip-kill-mysqld*) KILL_MYSQLD=0 ;;
188
183
--syslog) want_syslog=1 ;;
189
184
--skip-syslog) want_syslog=0 ;;
190
185
--syslog-tag=*) syslog_tag="$val" ;;
214
# Check for the directories we would expect from a binary release install
215
if test -f "$relpkgdata"/english/errmsg.sys -a -x ./bin/mysqld
217
MY_BASEDIR_VERSION=$MY_PWD # Where bin, share and data are
218
ledir=$MY_BASEDIR_VERSION/bin # Where mysqld is
219
219
# Check for the directories we would expect from a source install
220
if test -f "$prefix"/include/drizzled/error.h -a -x "${sbindir}"/drizzled
220
elif test -f "$relpkgdata"/english/errmsg.sys -a -x ./libexec/mysqld
222
222
MY_BASEDIR_VERSION=$MY_PWD # Where libexec, share and var are
223
ledir=$MY_BASEDIR_VERSION/libexec # Where mysqld is
223
224
# Since we didn't find anything, used the compiled-in defaults
225
226
MY_BASEDIR_VERSION=@prefix@
230
232
# Second, try to find the data directory
233
if test -d $MY_BASEDIR_VERSION/var
235
# Try where the binary installs put it
236
if test -d $MY_BASEDIR_VERSION/data/mysql
238
DATADIR=$MY_BASEDIR_VERSION/data
239
if test -z "$defaults" -a -r "$DATADIR/my.cnf"
241
defaults="--defaults-extra-file=$DATADIR/my.cnf"
243
# Next try where the source installs put it
244
elif test -d $MY_BASEDIR_VERSION/var/mysql
235
246
DATADIR=$MY_BASEDIR_VERSION/var
236
247
# Or just give up and use our compiled-in default
248
259
IGNORING $DATADIR/my.cnf"
250
DRIZZLE_HOME=$MY_BASEDIR_VERSION
261
MYSQL_HOME=$MY_BASEDIR_VERSION
251
262
elif test -r "$DATADIR/my.cnf"
253
264
log_error "WARNING: Found $DATADIR/my.cnf
254
265
The data directory is a deprecated location for my.cnf, please move it to
255
266
$MY_BASEDIR_VERSION/my.cnf"
256
DRIZZLE_HOME=$DATADIR
258
DRIZZLE_HOME=$MY_BASEDIR_VERSION
269
MYSQL_HOME=$MY_BASEDIR_VERSION
264
# Get first arguments from the my.cnf file, groups [drizzled] and [drizzled_safe]
275
# Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
265
276
# and then merge with the command line arguments
266
277
if test -x ./bin/my_print_defaults
286
parse_arguments `$print_defaults $defaults --loose-verbose drizzled server`
297
parse_arguments `$print_defaults $defaults --loose-verbose mysqld server`
287
298
if test $SET_USER -eq 2
292
parse_arguments `$print_defaults $defaults --loose-verbose drizzled_safe safe_drizzled`
303
parse_arguments `$print_defaults $defaults --loose-verbose mysqld_safe safe_mysqld`
293
304
parse_arguments PICK-ARGS-FROM-ARGV "$@"
295
306
# Determine what logging facility to use
300
311
my_which logger > /dev/null 2>&1
303
log_error "--syslog requested, but no 'logger' program found. Please ensure that 'logger' is in your PATH, or do not specify the --syslog option to drizzled_safe."
314
log_error "--syslog requested, but no 'logger' program found. Please ensure that 'logger' is in your PATH, or do not specify the --syslog option to mysqld_safe."
310
321
if [ -n "$err_log" ]
312
# drizzled adds ".err" if there is no extension on the --log-error
313
# argument; must match that here, or drizzled_safe will write to a
314
# different log file than drizzled
323
# mysqld adds ".err" if there is no extension on the --log-error
324
# argument; must match that here, or mysqld_safe will write to a
325
# different log file than mysqld
316
# drizzled does not add ".err" to "--log-error=foo."; it considers a
327
# mysqld does not add ".err" to "--log-error=foo."; it considers a
317
328
# trailing "." as an extension
318
329
if expr "$err_log" : '.*\.[^/]*$' > /dev/null
347
358
# Sanitize the syslog tag
348
359
syslog_tag=`echo "$syslog_tag" | sed -e 's/[^a-zA-Z0-9_-]/_/g'`
349
syslog_tag_drizzled_safe="${syslog_tag_drizzled_safe}-$syslog_tag"
350
syslog_tag_drizzled="${syslog_tag_drizzled}-$syslog_tag"
360
syslog_tag_mysqld_safe="${syslog_tag_mysqld_safe}-$syslog_tag"
361
syslog_tag_mysqld="${syslog_tag_mysqld}-$syslog_tag"
352
363
log_notice "Logging to syslog."
375
safe_mysql_unix_port=${mysql_unix_port:-${DRIZZLE_UNIX_PORT:-@DRIZZLE_UNIX_ADDR@}}
386
safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-@MYSQL_UNIX_ADDR@}}
376
387
# Make sure that directory for $safe_mysql_unix_port exists
377
388
mysql_unix_port_dir=`dirname $safe_mysql_unix_port`
378
389
if [ ! -d $mysql_unix_port_dir ]
382
393
chmod 755 $mysql_unix_port_dir
385
# If the user doesn't specify a binary, we assume name "drizzled"
386
if test -z "$DRIZZLED"
396
# If the user doesn't specify a binary, we assume name "mysqld"
391
if test ! -x $sbindir/$DRIZZLED
402
if test ! -x $ledir/$MYSQLD
393
log_error "The file $sbindir/$DRIZZLED
404
log_error "The file $ledir/$MYSQLD
394
405
does not exist or is not executable. Please cd to the mysql installation
395
406
directory and restart this script from there as follows:
397
See http://dev.mysql.com/doc/mysql/en/drizzled-safe.html for more information"
408
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information"
507
518
# checked and repaired during startup. You should add sensible key_buffer
508
519
# and sort_buffer values to my.cnf to improve check performance or require
509
520
# less disk space.
510
# Alternatively, you can start drizzled with the "myisam-recover" option. See
521
# Alternatively, you can start mysqld with the "myisam-recover" option. See
511
522
# the manual for details.
513
524
# echo "Checking tables in $DATADIR"
523
534
cmd="$NOHUP_NICENESS"
525
for i in "$sbindir/$DRIZZLED" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
536
for i in "$ledir/$MYSQLD" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
526
537
"--datadir=$DATADIR" "$USER_OPTION"
528
539
cmd="$cmd "`shell_quote_string "$i"`
531
542
# Avoid 'nohup: ignoring input' warning
532
543
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
534
log_notice "Starting $DRIZZLED daemon with databases from $DATADIR"
545
log_notice "Starting $MYSQLD daemon with databases from $DATADIR"
537
548
rm -f $safe_mysql_unix_port $pid_file # Some extra safety
546
if @TARGET_LINUX@ && test $KILL_DRIZZLED -eq 1
557
if @TARGET_LINUX@ && test $KILL_MYSQLD -eq 1
548
559
# Test if one process was hanging.
549
# This is only a fix for Linux (running as base 3 drizzled processes)
560
# This is only a fix for Linux (running as base 3 mysqld processes)
550
561
# but should work for the rest of the servers.
551
562
# The only thing is ps x => redhat 5 gives warnings when using ps -x.
552
563
# kill -9 is used or the process won't react on the kill.
553
numofproces=`ps xaww | grep -v "grep" | grep "$sbindir/$DRIZZLED\>" | grep -c "pid-file=$pid_file"`
564
numofproces=`ps xaww | grep -v "grep" | grep "$ledir/$MYSQLD\>" | grep -c "pid-file=$pid_file"`
555
566
log_notice "Number of processes running now: $numofproces"
557
568
while test "$I" -le "$numofproces"
559
PROC=`ps xaww | grep "$sbindir/$DRIZZLED\>" | grep -v "grep" | grep "pid-file=$pid_file" | sed -n '$p'`
570
PROC=`ps xaww | grep "$ledir/$MYSQLD\>" | grep -v "grep" | grep "pid-file=$pid_file" | sed -n '$p'`
565
576
# echo "TEST $I - $T **"
568
log_error "$DRIZZLED process hanging, pid $T - killed"
579
log_error "$MYSQLD process hanging, pid $T - killed"
575
log_notice "drizzled restarted"
586
log_notice "mysqld restarted"
578
log_notice "drizzled from pid file $pid_file ended"
589
log_notice "mysqld from pid file $pid_file ended"