~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to scripts/mysqld_safe.sh

  • Committer: Monty Taylor
  • Date: 2008-07-05 22:08:52 UTC
  • mto: This revision was merged to the branch mainline in revision 77.
  • Revision ID: monty@inaugust.com-20080705220852-cqd9t6tfkhvlcf73
Removed HAVE_LONG_LONG, as this is now assumed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
4
#
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
6
6
#
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
9
9
# location
10
10
#
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
13
13
 
14
 
KILL_DRIZZLED=1;
15
 
DRIZZLED=
 
14
KILL_MYSQLD=1;
 
15
MYSQLD=
16
16
niceness=0
17
17
# Initial logging status: error log is not open, and not using syslog
18
18
logging=init
19
19
want_syslog=0
20
20
syslog_tag=
21
 
user=@DRIZZLED_USER@
 
21
user=@MYSQLD_USER@
22
22
pid_file=
23
23
err_log=
24
24
 
25
 
prefix=@prefix@
26
 
exec_prefix=@exec_prefix@
27
 
sbindir=@sbindir@
28
 
libdir=@libdir@
29
 
includedir=@includedir@
30
 
 
31
 
 
32
 
syslog_tag_drizzled=drizzled
33
 
syslog_tag_drizzled_safe=drizzled_safe
 
25
syslog_tag_mysqld=mysqld
 
26
syslog_tag_mysqld_safe=mysqld_safe
34
27
 
35
28
trap '' 1 2 3 15                        # we shouldn't let anyone kill us
36
29
 
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'
62
56
 
63
 
All other options are passed to the drizzled program.
 
57
All other options are passed to the mysqld program.
64
58
 
65
59
EOF
66
60
        exit 1
95
89
  priority="$1"
96
90
  shift
97
91
 
98
 
  msg="`date +'%y%m%d %H:%M:%S'` drizzled_safe $*"
 
92
  msg="`date +'%y%m%d %H:%M:%S'` mysqld_safe $*"
99
93
  echo "$msg"
100
94
  case $logging in
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" "$*" ;;
104
98
    *)
105
99
      echo "Internal program error (non-fatal):" \
106
100
           " unknown logging method '$logging'" >&2
121
115
  case $logging in
122
116
    file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;;
123
117
    syslog)
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"
131
125
      ;;
132
126
    *)
133
127
      echo "Internal program error (non-fatal):" \
135
129
      ;;
136
130
  esac
137
131
 
138
 
  #echo "Running drizzled: [$cmd]"
 
132
  #echo "Running mysqld: [$cmd]"
139
133
  eval "$cmd"
140
134
}
141
135
 
159
153
  for arg do
160
154
    val=`echo "$arg" | sed -e "s;--[^=]*=;;"`
161
155
    case "$arg" in
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 ;;
167
161
 
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" ;;
173
167
 
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" ;;
 
172
      --mysqld-version=*)
178
173
        if test -n "$val"
179
174
        then
180
 
          DRIZZLED="drizzled-$val"
 
175
          MYSQLD="mysqld-$val"
181
176
        else
182
 
          DRIZZLED="drizzled"
 
177
          MYSQLD="mysqld"
183
178
        fi
184
179
        ;;
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" ;;
204
199
 
205
200
 
206
201
#
207
 
# First, try to find BASEDIR (where drizzled is)
 
202
# First, try to find BASEDIR and ledir (where mysqld is)
208
203
#
209
204
 
210
205
if echo '@pkgdatadir@' | grep '^@prefix@' > /dev/null
216
211
fi
217
212
 
218
213
MY_PWD=`pwd`
 
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
 
216
then
 
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
221
221
then
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
224
225
else
225
226
  MY_BASEDIR_VERSION=@prefix@
 
227
  ledir=@libexecdir@
226
228
fi
227
229
 
228
230
 
230
232
# Second, try to find the data directory
231
233
#
232
234
 
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
 
237
then
 
238
  DATADIR=$MY_BASEDIR_VERSION/data
 
239
  if test -z "$defaults" -a -r "$DATADIR/my.cnf"
 
240
  then
 
241
    defaults="--defaults-extra-file=$DATADIR/my.cnf"
 
242
  fi
 
243
# Next try where the source installs put it
 
244
elif test -d $MY_BASEDIR_VERSION/var/mysql
234
245
then
235
246
  DATADIR=$MY_BASEDIR_VERSION/var
236
247
# Or just give up and use our compiled-in default
238
249
  DATADIR=@localstatedir@
239
250
fi
240
251
 
241
 
if test -z "$DRIZZLE_HOME"
 
252
if test -z "$MYSQL_HOME"
242
253
then 
243
254
  if test -r "$MY_BASEDIR_VERSION/my.cnf" && test -r "$DATADIR/my.cnf"
244
255
  then
247
258
$DATADIR/my.cnf
248
259
IGNORING $DATADIR/my.cnf"
249
260
 
250
 
    DRIZZLE_HOME=$MY_BASEDIR_VERSION
 
261
    MYSQL_HOME=$MY_BASEDIR_VERSION
251
262
  elif test -r "$DATADIR/my.cnf"
252
263
  then
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
 
267
    MYSQL_HOME=$DATADIR
257
268
  else
258
 
    DRIZZLE_HOME=$MY_BASEDIR_VERSION
 
269
    MYSQL_HOME=$MY_BASEDIR_VERSION
259
270
  fi
260
271
fi
261
 
export DRIZZLE_HOME
262
 
 
263
 
 
264
 
# Get first arguments from the my.cnf file, groups [drizzled] and [drizzled_safe]
 
272
export MYSQL_HOME
 
273
 
 
274
 
 
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
267
278
then
283
294
args=
284
295
 
285
296
SET_USER=2
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
288
299
then
289
300
  SET_USER=0
290
301
fi
291
302
 
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 "$@"
294
305
 
295
306
# Determine what logging facility to use
300
311
  my_which logger > /dev/null 2>&1
301
312
  if [ $? -ne 0 ]
302
313
  then
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."
304
315
    exit 1
305
316
  fi
306
317
fi
309
320
then
310
321
  if [ -n "$err_log" ]
311
322
  then
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
315
326
 
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
319
330
    then
346
357
  then
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"
351
362
  fi
352
363
  log_notice "Logging to syslog."
353
364
  logging=syslog
372
383
  fi
373
384
fi
374
385
 
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
383
394
fi
384
395
 
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"
 
397
if test -z "$MYSQLD"
387
398
then
388
 
  DRIZZLED=drizzled
 
399
  MYSQLD=mysqld
389
400
fi
390
401
 
391
 
if test ! -x $sbindir/$DRIZZLED
 
402
if test ! -x $ledir/$MYSQLD
392
403
then
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:
396
 
./bin/drizzled_safe&
397
 
See http://dev.mysql.com/doc/mysql/en/drizzled-safe.html for more information"
 
407
./bin/mysqld_safe&
 
408
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information"
398
409
  exit 1
399
410
fi
400
411
 
486
497
  if @CHECK_PID@
487
498
  then
488
499
    if @FIND_PROC@
489
 
    then    # The pid contains a drizzled process
490
 
      log_error "A drizzled process already exists"
 
500
    then    # The pid contains a mysqld process
 
501
      log_error "A mysqld process already exists"
491
502
      exit 1
492
503
    fi
493
504
  fi
497
508
    log_error "Fatal error: Can't remove the pid file:
498
509
$pid_file
499
510
Please remove it manually and start $0 again;
500
 
drizzled daemon not started"
 
511
mysqld daemon not started"
501
512
    exit 1
502
513
  fi
503
514
fi
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.
512
523
#
513
524
# echo "Checking tables in $DATADIR"
522
533
 
523
534
cmd="$NOHUP_NICENESS"
524
535
 
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"
527
538
do
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"
533
544
 
534
 
log_notice "Starting $DRIZZLED daemon with databases from $DATADIR"
 
545
log_notice "Starting $MYSQLD daemon with databases from $DATADIR"
535
546
while true
536
547
do
537
548
  rm -f $safe_mysql_unix_port $pid_file # Some extra safety
543
554
    break
544
555
  fi
545
556
 
546
 
  if @TARGET_LINUX@ && test $KILL_DRIZZLED -eq 1
 
557
  if @TARGET_LINUX@ && test $KILL_MYSQLD -eq 1
547
558
  then
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"`
554
565
 
555
566
    log_notice "Number of processes running now: $numofproces"
556
567
    I=1
557
568
    while test "$I" -le "$numofproces"
558
569
    do 
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'` 
560
571
 
561
572
      for T in $PROC
562
573
      do
565
576
      #    echo "TEST $I - $T **"
566
577
      if kill -9 $T
567
578
      then
568
 
        log_error "$DRIZZLED process hanging, pid $T - killed"
 
579
        log_error "$MYSQLD process hanging, pid $T - killed"
569
580
      else
570
581
        break
571
582
      fi
572
583
      I=`expr $I + 1`
573
584
    done
574
585
  fi
575
 
  log_notice "drizzled restarted"
 
586
  log_notice "mysqld restarted"
576
587
done
577
588
 
578
 
log_notice "drizzled from pid file $pid_file ended"
 
589
log_notice "mysqld from pid file $pid_file ended"
579
590