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
# Script to start the Drizzle daemon and restart it if it dies unexpectedly
7
# This should be executed in the Drizzle base directory if you are using a
8
# binary installation that is not installed in its compile-time default
11
# mysql.server works by first doing a cd to the base directory and from there
12
# executing drizzled_safe
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
35
trap '' 1 2 3 15 # we shouldn't let anyone kill us
41
--no-defaults|--defaults-file=*|--defaults-extra-file=*)
49
--no-defaults Don't read the system defaults file
50
--defaults-file=FILE Use the specified defaults file
51
--defaults-extra-file=FILE Also use defaults from the specified file
52
--open-files-limit=LIMIT Limit the number of open files
53
--core-file-size=LIMIT Limit core files to the specified size
54
--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
59
--syslog Log messages to syslog with 'logger'
60
--skip-syslog Log messages to error log (default)
61
--syslog-tag=TAG Pass -t "drizzled-TAG" to 'logger'
63
All other options are passed to the drizzled program.
71
save_ifs="${IFS-UNSET}"
77
if [ -f "$dir/$file" ]
83
return 1 # Failure, didn't find file in path
85
if [ "$save_ifs" = UNSET ]
98
msg="`date +'%y%m%d %H:%M:%S'` drizzled_safe $*"
101
init) ;; # Just echo the message, don't save it anywhere
102
file) echo "$msg" >> "$err_log" ;;
103
syslog) logger -t "$syslog_tag_drizzled_safe" -p "$priority" "$*" ;;
105
echo "Internal program error (non-fatal):" \
106
" unknown logging method '$logging'" >&2
112
log_generic daemon.error "$@" >&2
116
log_generic daemon.notice "$@"
122
file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;;
124
# drizzled often prefixes its messages with a timestamp, which is
125
# redundant when logging to syslog (which adds its own timestamp)
126
# However, we don't strip the timestamp with sed here, because
127
# sed buffers output (only GNU sed supports a -u (unbuffered) option)
128
# 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"
133
echo "Internal program error (non-fatal):" \
134
" unknown logging method '$logging'" >&2
138
#echo "Running drizzled: [$cmd]"
142
shell_quote_string() {
143
# This sed command makes sure that any special chars are quoted,
144
# so the arg gets passed exactly to the server.
145
echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g'
149
# We only need to pass arguments through to the server if we don't
150
# handle them here. So, we collect unrecognized options (passed on
151
# the command line) into the args variable.
153
if test "$1" = PICK-ARGS-FROM-ARGV
160
val=`echo "$arg" | sed -e "s;--[^=]*=;;"`
162
# these get passed explicitly to drizzled
163
--basedir=*) MY_BASEDIR_VERSION="$val" ;;
164
--datadir=*) DATADIR="$val" ;;
165
--pid-file=*) pid_file="$val" ;;
166
--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
170
--log-error=*) err_log="$val" ;;
171
--port=*) mysql_tcp_port="$val" ;;
172
--socket=*) mysql_unix_port="$val" ;;
174
# drizzled_safe-specific options - must be set in my.cnf ([drizzled_safe])!
175
--core-file-size=*) core_file_size="$val" ;;
176
--drizzled=*) DRIZZLED="$val" ;;
177
--drizzled-version=*)
180
DRIZZLED="drizzled-$val"
185
--nice=*) niceness="$val" ;;
186
--open-files-limit=*) open_files="$val" ;;
187
--skip-kill-drizzled*) KILL_DRIZZLED=0 ;;
188
--syslog) want_syslog=1 ;;
189
--skip-syslog) want_syslog=0 ;;
190
--syslog-tag=*) syslog_tag="$val" ;;
191
--timezone=*) TZ="$val"; export TZ; ;;
196
if test -n "$pick_args"
198
append_arg_to_args "$arg"
207
# First, try to find BASEDIR (where drizzled is)
210
if echo '@pkgdatadir@' | grep '^@prefix@' > /dev/null
212
relpkgdata=`echo '@pkgdatadir@' | sed -e 's,^@prefix@,,' -e 's,^/,,' -e 's,^,./,'`
214
# pkgdatadir is not relative to prefix
215
relpkgdata='@pkgdatadir@'
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
222
MY_BASEDIR_VERSION=$MY_PWD # Where libexec, share and var are
223
# Since we didn't find anything, used the compiled-in defaults
225
MY_BASEDIR_VERSION=@prefix@
230
# Second, try to find the data directory
233
if test -d $MY_BASEDIR_VERSION/var
235
DATADIR=$MY_BASEDIR_VERSION/var
236
# Or just give up and use our compiled-in default
238
DATADIR=@localstatedir@
241
if test -z "$DRIZZLE_HOME"
243
if test -r "$MY_BASEDIR_VERSION/my.cnf" && test -r "$DATADIR/my.cnf"
245
log_error "WARNING: Found two instances of my.cnf -
246
$MY_BASEDIR_VERSION/my.cnf and
248
IGNORING $DATADIR/my.cnf"
250
DRIZZLE_HOME=$MY_BASEDIR_VERSION
251
elif test -r "$DATADIR/my.cnf"
253
log_error "WARNING: Found $DATADIR/my.cnf
254
The data directory is a deprecated location for my.cnf, please move it to
255
$MY_BASEDIR_VERSION/my.cnf"
256
DRIZZLE_HOME=$DATADIR
258
DRIZZLE_HOME=$MY_BASEDIR_VERSION
264
# Get first arguments from the my.cnf file, groups [drizzled] and [drizzled_safe]
265
# and then merge with the command line arguments
266
if test -x ./bin/my_print_defaults
268
print_defaults="./bin/my_print_defaults"
269
elif test -x @bindir@/my_print_defaults
271
print_defaults="@bindir@/my_print_defaults"
272
elif test -x @bindir@/mysql_print_defaults
274
print_defaults="@bindir@/mysql_print_defaults"
276
print_defaults="my_print_defaults"
279
append_arg_to_args () {
280
args="$args "`shell_quote_string "$1"`
286
parse_arguments `$print_defaults $defaults --loose-verbose drizzled server`
287
if test $SET_USER -eq 2
292
parse_arguments `$print_defaults $defaults --loose-verbose drizzled_safe safe_drizzled`
293
parse_arguments PICK-ARGS-FROM-ARGV "$@"
295
# Determine what logging facility to use
297
# Ensure that 'logger' exists, if it's requested
298
if [ $want_syslog -eq 1 ]
300
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."
308
if [ -n "$err_log" -o $want_syslog -eq 0 ]
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
316
# drizzled does not add ".err" to "--log-error=foo."; it considers a
317
# trailing "." as an extension
318
if expr "$err_log" : '.*\.[^/]*$' > /dev/null
322
err_log="$err_log".err
327
* ) err_log="$DATADIR/$err_log" ;;
330
err_log=$DATADIR/`@HOSTNAME@`.err
333
append_arg_to_args "--log-error=$err_log"
335
if [ $want_syslog -eq 1 ]
337
# User explicitly asked for syslog, so warn that it isn't used
338
log_error "Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect."
341
# Log to err_log file
342
log_notice "Logging to '$err_log'."
345
if [ -n "$syslog_tag" ]
347
# Sanitize the syslog tag
348
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"
352
log_notice "Logging to syslog."
357
if test -w / -o "$USER" = "root"
359
if test "$user" != "root" -o $SET_USER = 1
361
USER_OPTION="--user=$user"
363
# Change the err log to the right user, if it is in use
364
if [ $want_syslog -eq 0 ]; then
368
if test -n "$open_files"
370
ulimit -n $open_files
371
append_arg_to_args "--open-files-limit=$open_files"
375
safe_mysql_unix_port=${mysql_unix_port:-${DRIZZLE_UNIX_PORT:-@DRIZZLE_UNIX_ADDR@}}
376
# Make sure that directory for $safe_mysql_unix_port exists
377
mysql_unix_port_dir=`dirname $safe_mysql_unix_port`
378
if [ ! -d $mysql_unix_port_dir ]
380
mkdir $mysql_unix_port_dir
381
chown $user $mysql_unix_port_dir
382
chmod 755 $mysql_unix_port_dir
385
# If the user doesn't specify a binary, we assume name "drizzled"
386
if test -z "$DRIZZLED"
391
if test ! -x $sbindir/$DRIZZLED
393
log_error "The file $sbindir/$DRIZZLED
394
does not exist or is not executable. Please cd to the mysql installation
395
directory and restart this script from there as follows:
397
See http://dev.mysql.com/doc/mysql/en/drizzled-safe.html for more information"
401
if test -z "$pid_file"
403
pid_file=$DATADIR/`@HOSTNAME@`.pid
407
* ) pid_file="$DATADIR/$pid_file" ;;
410
append_arg_to_args "--pid-file=$pid_file"
412
if test -n "$mysql_unix_port"
414
append_arg_to_args "--socket=$mysql_unix_port"
416
if test -n "$mysql_tcp_port"
418
append_arg_to_args "--port=$mysql_tcp_port"
421
if test $niceness -eq 0
423
NOHUP_NICENESS="nohup"
425
NOHUP_NICENESS="nohup nice -$niceness"
428
# Using nice with no args to get the niceness level is GNU-specific.
429
# This check could be extended for other operating systems (e.g.,
430
# BSD could use "nohup sh -c 'ps -o nice -p $$' | tail -1").
431
# But, it also seems that GNU nohup is the only one which messes
432
# with the priority, so this is okay.
433
if nohup nice > /dev/null 2>&1
435
normal_niceness=`nice`
436
nohup_niceness=`nohup nice 2>/dev/null`
438
numeric_nice_values=1
439
for val in $normal_niceness $nohup_niceness
442
-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | \
443
[0-9] | [0-9][0-9] | [0-9][0-9][0-9] )
446
numeric_nice_values=0 ;;
450
if test $numeric_nice_values -eq 1
452
nice_value_diff=`expr $nohup_niceness - $normal_niceness`
453
if test $? -eq 0 && test $nice_value_diff -gt 0 && \
454
nice --$nice_value_diff echo testing > /dev/null 2>&1
456
# nohup increases the priority (bad), and we are permitted
457
# to lower the priority with respect to the value the user
458
# might have been given
459
niceness=`expr $niceness - $nice_value_diff`
460
NOHUP_NICENESS="nice -$niceness nohup"
464
if nohup echo testing > /dev/null 2>&1
468
# nohup doesn't work on this system
473
# Try to set the core file size (even if we aren't root) because many systems
474
# don't specify a hard limit on core file size.
475
if test -n "$core_file_size"
477
ulimit -c $core_file_size
481
# If there exists an old pid file, check if the daemon is already running
482
# Note: The switches to 'ps' may depend on your operating system
489
then # The pid contains a drizzled process
490
log_error "A drizzled process already exists"
497
log_error "Fatal error: Can't remove the pid file:
499
Please remove it manually and start $0 again;
500
drizzled daemon not started"
506
# Uncomment the following lines if you want all tables to be automatically
507
# checked and repaired during startup. You should add sensible key_buffer
508
# and sort_buffer values to my.cnf to improve check performance or require
510
# Alternatively, you can start drizzled with the "myisam-recover" option. See
511
# the manual for details.
513
# echo "Checking tables in $DATADIR"
514
# $MY_BASEDIR_VERSION/bin/myisamchk --silent --force --fast --medium-check $DATADIR/*/*.MYI
515
# $MY_BASEDIR_VERSION/bin/isamchk --silent --force $DATADIR/*/*.ISM
517
# Does this work on all systems?
518
#if type ulimit | grep "shell builtin" > /dev/null
520
# ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems
523
cmd="$NOHUP_NICENESS"
525
for i in "$sbindir/$DRIZZLED" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
526
"--datadir=$DATADIR" "$USER_OPTION"
528
cmd="$cmd "`shell_quote_string "$i"`
531
# Avoid 'nohup: ignoring input' warning
532
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
534
log_notice "Starting $DRIZZLED daemon with databases from $DATADIR"
537
rm -f $safe_mysql_unix_port $pid_file # Some extra safety
539
eval_log_error "$cmd"
541
if test ! -f $pid_file # This is removed if normal shutdown
546
if @TARGET_LINUX@ && test $KILL_DRIZZLED -eq 1
548
# Test if one process was hanging.
549
# This is only a fix for Linux (running as base 3 drizzled processes)
550
# but should work for the rest of the servers.
551
# The only thing is ps x => redhat 5 gives warnings when using ps -x.
552
# 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"`
555
log_notice "Number of processes running now: $numofproces"
557
while test "$I" -le "$numofproces"
559
PROC=`ps xaww | grep "$sbindir/$DRIZZLED\>" | grep -v "grep" | grep "pid-file=$pid_file" | sed -n '$p'`
565
# echo "TEST $I - $T **"
568
log_error "$DRIZZLED process hanging, pid $T - killed"
575
log_notice "drizzled restarted"
578
log_notice "drizzled from pid file $pid_file ended"