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
--core-file-size=LIMIT Limit core files to the specified size
53
--timezone=TZ Set the system timezone
54
--drizzled=FILE Use the specified file as drizzled
55
--drizzled-version=VERSION Use "drizzled-VERSION" as drizzled
56
--nice=NICE Set the scheduling priority of drizzled
57
--skip-kill-drizzled Don't try to kill stray drizzled processes
58
--syslog Log messages to syslog with 'logger'
59
--skip-syslog Log messages to error log (default)
60
--syslog-tag=TAG Pass -t "drizzled-TAG" to 'logger'
62
All other options are passed to the drizzled program.
70
save_ifs="${IFS-UNSET}"
76
if [ -f "$dir/$file" ]
82
return 1 # Failure, didn't find file in path
84
if [ "$save_ifs" = UNSET ]
97
msg="`date +'%y%m%d %H:%M:%S'` drizzled_safe $*"
100
init) ;; # Just echo the message, don't save it anywhere
101
file) echo "$msg" >> "$err_log" ;;
102
syslog) logger -t "$syslog_tag_drizzled_safe" -p "$priority" "$*" ;;
104
echo "Internal program error (non-fatal):" \
105
" unknown logging method '$logging'" >&2
111
log_generic daemon.error "$@" >&2
115
log_generic daemon.notice "$@"
121
file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;;
123
# drizzled often prefixes its messages with a timestamp, which is
124
# redundant when logging to syslog (which adds its own timestamp)
125
# However, we don't strip the timestamp with sed here, because
126
# sed buffers output (only GNU sed supports a -u (unbuffered) option)
127
# which means that messages may not get sent to syslog until the
128
# drizzled process quits.
129
cmd="$cmd 2>&1 | logger -t '$syslog_tag_drizzled' -p daemon.error"
132
echo "Internal program error (non-fatal):" \
133
" unknown logging method '$logging'" >&2
137
#echo "Running drizzled: [$cmd]"
141
shell_quote_string() {
142
# This sed command makes sure that any special chars are quoted,
143
# so the arg gets passed exactly to the server.
144
echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g'
148
# We only need to pass arguments through to the server if we don't
149
# handle them here. So, we collect unrecognized options (passed on
150
# the command line) into the args variable.
152
if test "$1" = PICK-ARGS-FROM-ARGV
159
val=`echo "$arg" | sed -e "s;--[^=]*=;;"`
161
# these get passed explicitly to drizzled
162
--basedir=*) MY_BASEDIR_VERSION="$val" ;;
163
--datadir=*) DATADIR="$val" ;;
164
--pid-file=*) pid_file="$val" ;;
165
--user=*) user="$val"; SET_USER=1 ;;
167
# these might have been set in a [drizzled_safe] section of my.cnf
168
# they are added to drizzled command line to override settings from my.cnf
169
--log-error=*) err_log="$val" ;;
170
--port=*) mysql_tcp_port="$val" ;;
171
--socket=*) mysql_unix_port="$val" ;;
173
# drizzled_safe-specific options - must be set in my.cnf ([drizzled_safe])!
174
--core-file-size=*) core_file_size="$val" ;;
175
--drizzled=*) DRIZZLED="$val" ;;
176
--drizzled-version=*)
179
DRIZZLED="drizzled-$val"
184
--nice=*) niceness="$val" ;;
185
--skip-kill-drizzled*) KILL_DRIZZLED=0 ;;
186
--syslog) want_syslog=1 ;;
187
--skip-syslog) want_syslog=0 ;;
188
--syslog-tag=*) syslog_tag="$val" ;;
189
--timezone=*) TZ="$val"; export TZ; ;;
194
if test -n "$pick_args"
196
append_arg_to_args "$arg"
205
# First, try to find BASEDIR (where drizzled is)
208
if echo '@pkgdatadir@' | grep '^@prefix@' > /dev/null
210
relpkgdata=`echo '@pkgdatadir@' | sed -e 's,^@prefix@,,' -e 's,^/,,' -e 's,^,./,'`
212
# pkgdatadir is not relative to prefix
213
relpkgdata='@pkgdatadir@'
217
# Check for the directories we would expect from a source install
218
if test -f "$prefix"/include/drizzled/error.h -a -x "${sbindir}"/drizzled
220
MY_BASEDIR_VERSION=$MY_PWD # Where libexec, share and var are
221
# Since we didn't find anything, used the compiled-in defaults
223
MY_BASEDIR_VERSION=@prefix@
228
# Second, try to find the data directory
231
if test -d $MY_BASEDIR_VERSION/var
233
DATADIR=$MY_BASEDIR_VERSION/var
234
# Or just give up and use our compiled-in default
236
DATADIR=@localstatedir@
239
if test -z "$DRIZZLE_HOME"
241
if test -r "$MY_BASEDIR_VERSION/my.cnf" && test -r "$DATADIR/my.cnf"
243
log_error "WARNING: Found two instances of my.cnf -
244
$MY_BASEDIR_VERSION/my.cnf and
246
IGNORING $DATADIR/my.cnf"
248
DRIZZLE_HOME=$MY_BASEDIR_VERSION
249
elif test -r "$DATADIR/my.cnf"
251
log_error "WARNING: Found $DATADIR/my.cnf
252
The data directory is a deprecated location for my.cnf, please move it to
253
$MY_BASEDIR_VERSION/my.cnf"
254
DRIZZLE_HOME=$DATADIR
256
DRIZZLE_HOME=$MY_BASEDIR_VERSION
262
# Get first arguments from the my.cnf file, groups [drizzled] and [drizzled_safe]
263
# and then merge with the command line arguments
264
if test -x ./bin/my_print_defaults
266
print_defaults="./bin/my_print_defaults"
267
elif test -x @bindir@/my_print_defaults
269
print_defaults="@bindir@/my_print_defaults"
270
elif test -x @bindir@/mysql_print_defaults
272
print_defaults="@bindir@/mysql_print_defaults"
274
print_defaults="my_print_defaults"
277
append_arg_to_args () {
278
args="$args "`shell_quote_string "$1"`
284
parse_arguments `$print_defaults $defaults --loose-verbose drizzled server`
285
if test $SET_USER -eq 2
290
parse_arguments `$print_defaults $defaults --loose-verbose drizzled_safe safe_drizzled`
291
parse_arguments PICK-ARGS-FROM-ARGV "$@"
293
# Determine what logging facility to use
295
# Ensure that 'logger' exists, if it's requested
296
if [ $want_syslog -eq 1 ]
298
my_which logger > /dev/null 2>&1
301
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."
306
if [ -n "$err_log" -o $want_syslog -eq 0 ]
310
# drizzled adds ".err" if there is no extension on the --log-error
311
# argument; must match that here, or drizzled_safe will write to a
312
# different log file than drizzled
314
# drizzled does not add ".err" to "--log-error=foo."; it considers a
315
# trailing "." as an extension
316
if expr "$err_log" : '.*\.[^/]*$' > /dev/null
320
err_log="$err_log".err
325
* ) err_log="$DATADIR/$err_log" ;;
328
err_log=$DATADIR/`@HOSTNAME@`.err
331
append_arg_to_args "--log-error=$err_log"
333
if [ $want_syslog -eq 1 ]
335
# User explicitly asked for syslog, so warn that it isn't used
336
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."
339
# Log to err_log file
340
log_notice "Logging to '$err_log'."
343
if [ -n "$syslog_tag" ]
345
# Sanitize the syslog tag
346
syslog_tag=`echo "$syslog_tag" | sed -e 's/[^a-zA-Z0-9_-]/_/g'`
347
syslog_tag_drizzled_safe="${syslog_tag_drizzled_safe}-$syslog_tag"
348
syslog_tag_drizzled="${syslog_tag_drizzled}-$syslog_tag"
350
log_notice "Logging to syslog."
355
if test -w / -o "$USER" = "root"
357
if test "$user" != "root" -o $SET_USER = 1
359
USER_OPTION="--user=$user"
361
# Change the err log to the right user, if it is in use
362
if [ $want_syslog -eq 0 ]; then
366
if test -n "$open_files"
368
ulimit -n $open_files
372
safe_mysql_unix_port=${mysql_unix_port:-${DRIZZLE_UNIX_PORT:-@DRIZZLE_UNIX_ADDR@}}
373
# Make sure that directory for $safe_mysql_unix_port exists
374
mysql_unix_port_dir=`dirname $safe_mysql_unix_port`
375
if [ ! -d $mysql_unix_port_dir ]
377
mkdir $mysql_unix_port_dir
378
chown $user $mysql_unix_port_dir
379
chmod 755 $mysql_unix_port_dir
382
# If the user doesn't specify a binary, we assume name "drizzled"
383
if test -z "$DRIZZLED"
388
if test ! -x $sbindir/$DRIZZLED
390
log_error "The file $sbindir/$DRIZZLED
391
does not exist or is not executable. Please cd to the mysql installation
392
directory and restart this script from there as follows:
398
if test -z "$pid_file"
400
pid_file=$DATADIR/`@HOSTNAME@`.pid
404
* ) pid_file="$DATADIR/$pid_file" ;;
407
append_arg_to_args "--pid-file=$pid_file"
409
if test -n "$mysql_unix_port"
411
append_arg_to_args "--socket=$mysql_unix_port"
413
if test -n "$mysql_tcp_port"
415
append_arg_to_args "--port=$mysql_tcp_port"
418
if test $niceness -eq 0
420
NOHUP_NICENESS="nohup"
422
NOHUP_NICENESS="nohup nice -$niceness"
425
# Using nice with no args to get the niceness level is GNU-specific.
426
# This check could be extended for other operating systems (e.g.,
427
# BSD could use "nohup sh -c 'ps -o nice -p $$' | tail -1").
428
# But, it also seems that GNU nohup is the only one which messes
429
# with the priority, so this is okay.
430
if nohup nice > /dev/null 2>&1
432
normal_niceness=`nice`
433
nohup_niceness=`nohup nice 2>/dev/null`
435
numeric_nice_values=1
436
for val in $normal_niceness $nohup_niceness
439
-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | \
440
[0-9] | [0-9][0-9] | [0-9][0-9][0-9] )
443
numeric_nice_values=0 ;;
447
if test $numeric_nice_values -eq 1
449
nice_value_diff=`expr $nohup_niceness - $normal_niceness`
450
if test $? -eq 0 && test $nice_value_diff -gt 0 && \
451
nice --$nice_value_diff echo testing > /dev/null 2>&1
453
# nohup increases the priority (bad), and we are permitted
454
# to lower the priority with respect to the value the user
455
# might have been given
456
niceness=`expr $niceness - $nice_value_diff`
457
NOHUP_NICENESS="nice -$niceness nohup"
461
if nohup echo testing > /dev/null 2>&1
465
# nohup doesn't work on this system
470
# Try to set the core file size (even if we aren't root) because many systems
471
# don't specify a hard limit on core file size.
472
if test -n "$core_file_size"
474
ulimit -c $core_file_size
478
# If there exists an old pid file, check if the daemon is already running
479
# Note: The switches to 'ps' may depend on your operating system
486
then # The pid contains a drizzled process
487
log_error "A drizzled process already exists"
494
log_error "Fatal error: Can't remove the pid file:
496
Please remove it manually and start $0 again;
497
drizzled daemon not started"
503
# Uncomment the following lines if you want all tables to be automatically
504
# checked and repaired during startup. You should add sensible key_buffer
505
# and sort_buffer values to my.cnf to improve check performance or require
507
# Alternatively, you can start drizzled with the "myisam-recover" option. See
508
# the manual for details.
510
# echo "Checking tables in $DATADIR"
511
# $MY_BASEDIR_VERSION/bin/myisamchk --silent --force --fast --medium-check $DATADIR/*/*.MYI
512
# $MY_BASEDIR_VERSION/bin/isamchk --silent --force $DATADIR/*/*.ISM
514
# Does this work on all systems?
515
#if type ulimit | grep "shell builtin" > /dev/null
517
# ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems
520
cmd="$NOHUP_NICENESS"
522
for i in "$sbindir/$DRIZZLED" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
523
"--datadir=$DATADIR" "$USER_OPTION"
525
cmd="$cmd "`shell_quote_string "$i"`
528
# Avoid 'nohup: ignoring input' warning
529
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
531
log_notice "Starting $DRIZZLED daemon with databases from $DATADIR"
534
rm -f $safe_mysql_unix_port $pid_file # Some extra safety
536
eval_log_error "$cmd"
538
if test ! -f $pid_file # This is removed if normal shutdown
543
if @TARGET_LINUX@ && test $KILL_DRIZZLED -eq 1
545
# Test if one process was hanging.
546
# This is only a fix for Linux (running as base 3 drizzled processes)
547
# but should work for the rest of the servers.
548
# The only thing is ps x => redhat 5 gives warnings when using ps -x.
549
# kill -9 is used or the process won't react on the kill.
550
numofproces=`ps xaww | grep -v "grep" | grep "$sbindir/$DRIZZLED\>" | grep -c "pid-file=$pid_file"`
552
log_notice "Number of processes running now: $numofproces"
554
while test "$I" -le "$numofproces"
556
PROC=`ps xaww | grep "$sbindir/$DRIZZLED\>" | grep -v "grep" | grep "pid-file=$pid_file" | sed -n '$p'`
562
# echo "TEST $I - $T **"
565
log_error "$DRIZZLED process hanging, pid $T - killed"
572
log_notice "drizzled restarted"
575
log_notice "drizzled from pid file $pid_file ended"