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 MySQL daemon and restart it if it dies unexpectedly
5
# Script to start the Drizzle daemon and restart it if it dies unexpectedly
7
# This should be executed in the MySQL base directory if you are using a
7
# This should be executed in the Drizzle 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 mysqld_safe
12
# executing drizzled_safe
17
17
# Initial logging status: error log is not open, and not using syslog
25
syslog_tag_mysqld=mysqld
26
syslog_tag_mysqld_safe=mysqld_safe
25
syslog_tag_drizzled=drizzled
26
syslog_tag_drizzled_safe=drizzled_safe
28
28
trap '' 1 2 3 15 # we shouldn't let anyone kill us
42
42
--no-defaults Don't read the system defaults file
43
43
--defaults-file=FILE Use the specified defaults file
44
44
--defaults-extra-file=FILE Also use defaults from the specified file
45
--ledir=DIRECTORY Look for mysqld in the specified directory
45
--ledir=DIRECTORY Look for drizzled in the specified directory
46
46
--open-files-limit=LIMIT Limit the number of open files
47
47
--core-file-size=LIMIT Limit core files to the specified size
48
48
--timezone=TZ Set the system timezone
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
49
--drizzled=FILE Use the specified file as drizzled
50
--drizzled-version=VERSION Use "drizzled-VERSION" as drizzled
51
--nice=NICE Set the scheduling priority of drizzled
52
--skip-kill-drizzled Don't try to kill stray drizzled processes
53
53
--syslog Log messages to syslog with 'logger'
54
54
--skip-syslog Log messages to error log (default)
55
--syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger'
55
--syslog-tag=TAG Pass -t "drizzled-TAG" to 'logger'
57
All other options are passed to the mysqld program.
57
All other options are passed to the drizzled program.
92
msg="`date +'%y%m%d %H:%M:%S'` mysqld_safe $*"
92
msg="`date +'%y%m%d %H:%M:%S'` drizzled_safe $*"
95
95
init) ;; # Just echo the message, don't save it anywhere
96
96
file) echo "$msg" >> "$err_log" ;;
97
syslog) logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;;
97
syslog) logger -t "$syslog_tag_drizzled_safe" -p "$priority" "$*" ;;
99
99
echo "Internal program error (non-fatal):" \
100
100
" unknown logging method '$logging'" >&2
116
116
file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;;
118
# mysqld often prefixes its messages with a timestamp, which is
118
# drizzled often prefixes its messages with a timestamp, which is
119
119
# redundant when logging to syslog (which adds its own timestamp)
120
120
# However, we don't strip the timestamp with sed here, because
121
121
# sed buffers output (only GNU sed supports a -u (unbuffered) option)
122
122
# which means that messages may not get sent to syslog until the
123
# mysqld process quits.
124
cmd="$cmd 2>&1 | logger -t '$syslog_tag_mysqld' -p daemon.error"
123
# drizzled process quits.
124
cmd="$cmd 2>&1 | logger -t '$syslog_tag_drizzled' -p daemon.error"
127
127
echo "Internal program error (non-fatal):" \
154
154
val=`echo "$arg" | sed -e "s;--[^=]*=;;"`
156
# these get passed explicitly to mysqld
156
# these get passed explicitly to drizzled
157
157
--basedir=*) MY_BASEDIR_VERSION="$val" ;;
158
158
--datadir=*) DATADIR="$val" ;;
159
159
--pid-file=*) pid_file="$val" ;;
160
160
--user=*) user="$val"; SET_USER=1 ;;
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
162
# these might have been set in a [drizzled_safe] section of my.cnf
163
# they are added to drizzled command line to override settings from my.cnf
164
164
--log-error=*) err_log="$val" ;;
165
165
--port=*) mysql_tcp_port="$val" ;;
166
166
--socket=*) mysql_unix_port="$val" ;;
168
# mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
168
# drizzled_safe-specific options - must be set in my.cnf ([drizzled_safe])!
169
169
--core-file-size=*) core_file_size="$val" ;;
170
170
--ledir=*) ledir="$val" ;;
171
--mysqld=*) MYSQLD="$val" ;;
171
--drizzled=*) DRIZZLED="$val" ;;
172
--drizzled-version=*)
173
173
if test -n "$val"
175
DRIZZLED="drizzled-$val"
180
180
--nice=*) niceness="$val" ;;
181
181
--open-files-limit=*) open_files="$val" ;;
182
--skip-kill-mysqld*) KILL_MYSQLD=0 ;;
182
--skip-kill-drizzled*) KILL_DRIZZLED=0 ;;
183
183
--syslog) want_syslog=1 ;;
184
184
--skip-syslog) want_syslog=0 ;;
185
185
--syslog-tag=*) syslog_tag="$val" ;;
214
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
215
if test -f "$relpkgdata"/english/errmsg.sys -a -x ./bin/drizzled
217
217
MY_BASEDIR_VERSION=$MY_PWD # Where bin, share and data are
218
ledir=$MY_BASEDIR_VERSION/bin # Where mysqld is
218
ledir=$MY_BASEDIR_VERSION/bin # Where drizzled is
219
219
# Check for the directories we would expect from a source install
220
elif test -f "$relpkgdata"/english/errmsg.sys -a -x ./libexec/mysqld
220
elif test -f "$relpkgdata"/english/errmsg.sys -a -x ./libexec/drizzled
222
222
MY_BASEDIR_VERSION=$MY_PWD # Where libexec, share and var are
223
ledir=$MY_BASEDIR_VERSION/libexec # Where mysqld is
223
ledir=$MY_BASEDIR_VERSION/libexec # Where drizzled is
224
224
# Since we didn't find anything, used the compiled-in defaults
226
226
MY_BASEDIR_VERSION=@prefix@
272
272
export MYSQL_HOME
275
# Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
275
# Get first arguments from the my.cnf file, groups [drizzled] and [drizzled_safe]
276
276
# and then merge with the command line arguments
277
277
if test -x ./bin/my_print_defaults
297
parse_arguments `$print_defaults $defaults --loose-verbose mysqld server`
297
parse_arguments `$print_defaults $defaults --loose-verbose drizzled server`
298
298
if test $SET_USER -eq 2
303
parse_arguments `$print_defaults $defaults --loose-verbose mysqld_safe safe_mysqld`
303
parse_arguments `$print_defaults $defaults --loose-verbose drizzled_safe safe_drizzled`
304
304
parse_arguments PICK-ARGS-FROM-ARGV "$@"
306
306
# Determine what logging facility to use
311
311
my_which logger > /dev/null 2>&1
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."
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 drizzled_safe."
321
321
if [ -n "$err_log" ]
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
323
# drizzled adds ".err" if there is no extension on the --log-error
324
# argument; must match that here, or drizzled_safe will write to a
325
# different log file than drizzled
327
# mysqld does not add ".err" to "--log-error=foo."; it considers a
327
# drizzled does not add ".err" to "--log-error=foo."; it considers a
328
328
# trailing "." as an extension
329
329
if expr "$err_log" : '.*\.[^/]*$' > /dev/null
358
358
# Sanitize the syslog tag
359
359
syslog_tag=`echo "$syslog_tag" | sed -e 's/[^a-zA-Z0-9_-]/_/g'`
360
syslog_tag_mysqld_safe="${syslog_tag_mysqld_safe}-$syslog_tag"
361
syslog_tag_mysqld="${syslog_tag_mysqld}-$syslog_tag"
360
syslog_tag_drizzled_safe="${syslog_tag_drizzled_safe}-$syslog_tag"
361
syslog_tag_drizzled="${syslog_tag_drizzled}-$syslog_tag"
363
363
log_notice "Logging to syslog."
393
393
chmod 755 $mysql_unix_port_dir
396
# If the user doesn't specify a binary, we assume name "mysqld"
396
# If the user doesn't specify a binary, we assume name "drizzled"
397
if test -z "$DRIZZLED"
402
if test ! -x $ledir/$MYSQLD
402
if test ! -x $ledir/$DRIZZLED
404
log_error "The file $ledir/$MYSQLD
404
log_error "The file $ledir/$DRIZZLED
405
405
does not exist or is not executable. Please cd to the mysql installation
406
406
directory and restart this script from there as follows:
408
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information"
408
See http://dev.mysql.com/doc/mysql/en/drizzled-safe.html for more information"
518
518
# checked and repaired during startup. You should add sensible key_buffer
519
519
# and sort_buffer values to my.cnf to improve check performance or require
520
520
# less disk space.
521
# Alternatively, you can start mysqld with the "myisam-recover" option. See
521
# Alternatively, you can start drizzled with the "myisam-recover" option. See
522
522
# the manual for details.
524
524
# echo "Checking tables in $DATADIR"
534
534
cmd="$NOHUP_NICENESS"
536
for i in "$ledir/$MYSQLD" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
536
for i in "$ledir/$DRIZZLED" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
537
537
"--datadir=$DATADIR" "$USER_OPTION"
539
539
cmd="$cmd "`shell_quote_string "$i"`
542
542
# Avoid 'nohup: ignoring input' warning
543
543
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
545
log_notice "Starting $MYSQLD daemon with databases from $DATADIR"
545
log_notice "Starting $DRIZZLED daemon with databases from $DATADIR"
548
548
rm -f $safe_mysql_unix_port $pid_file # Some extra safety
557
if @TARGET_LINUX@ && test $KILL_MYSQLD -eq 1
557
if @TARGET_LINUX@ && test $KILL_DRIZZLED -eq 1
559
559
# Test if one process was hanging.
560
# This is only a fix for Linux (running as base 3 mysqld processes)
560
# This is only a fix for Linux (running as base 3 drizzled processes)
561
561
# but should work for the rest of the servers.
562
562
# The only thing is ps x => redhat 5 gives warnings when using ps -x.
563
563
# kill -9 is used or the process won't react on the kill.
564
numofproces=`ps xaww | grep -v "grep" | grep "$ledir/$MYSQLD\>" | grep -c "pid-file=$pid_file"`
564
numofproces=`ps xaww | grep -v "grep" | grep "$ledir/$DRIZZLED\>" | grep -c "pid-file=$pid_file"`
566
566
log_notice "Number of processes running now: $numofproces"
568
568
while test "$I" -le "$numofproces"
570
PROC=`ps xaww | grep "$ledir/$MYSQLD\>" | grep -v "grep" | grep "pid-file=$pid_file" | sed -n '$p'`
570
PROC=`ps xaww | grep "$ledir/$DRIZZLED\>" | grep -v "grep" | grep "pid-file=$pid_file" | sed -n '$p'`
576
576
# echo "TEST $I - $T **"
579
log_error "$MYSQLD process hanging, pid $T - killed"
579
log_error "$DRIZZLED process hanging, pid $T - killed"
586
log_notice "mysqld restarted"
586
log_notice "drizzled restarted"
589
log_notice "mysqld from pid file $pid_file ended"
589
log_notice "drizzled from pid file $pid_file ended"