2.mysql-server.sh.in 2.84 KB
Newer Older
1 2
#!/bin/sh

3 4 5 6 7
# PROVIDE: mysql
# REQUIRE: NETWORKING SERVERS mysql-client
# BEFORE: DAEMON
# KEYWORD: shutdown

8
MAINSITE="@TBMAINSITE@"
9
BIGDB="@BIGDB@"
10

11
# On FreeBSD 6.X we need to wrap the wrapper with daemon to prevent HUP signal
12
fbsdvers=`uname -v | sed -e 's/FreeBSD \([0-9][0-9]*\).*/FreeBSD\1/'`
13

14 15 16 17
version=`/usr/local/bin/mysql_config --version`;
majmin=${version%.*}
major=${majmin%%.*}
minor=${majmin##*.}
18

19
opts="-O long_query_time=2 --skip-innodb"
20 21
if [ $MAINSITE == "0" -a $BIGDB == "0" ]; then
    opts="$opts -O key_buffer=32M -O table_cache=128 -O sort_buffer=2M"
22 23
    opts="$opts -O record_buffer=1M -O max_connections=250"
else
24
    opts="$opts -O key_buffer=256M -O table_cache=256 -O sort_buffer=4M"
25 26 27 28 29 30
    opts="$opts -O record_buffer=1M -O query_cache_size=16M"
    opts="$opts -O join_buffer_size=256K -O thread_cache_size=4"
    opts="$opts -O tmp_table_size=32M -O max_heap_table_size=32M"
    opts="$opts -O max_connections=350"
fi

31
logopt="--log-long-format --log=@prefix@/log/mysql/base --log-bin=@prefix@/log/mysql/update --log-slow-queries=@prefix@/log/mysql/slowqueries"
32 33 34 35 36

if [ $major -eq 5 ]; then
	safeprog=/usr/local/bin/mysqld_safe
	if [ $minor -gt 1 ]; then
	    logopt="--general_log=1 --general_log_file=@prefix@/log/mysql/base"
37
	    logopt="$logopt --log-bin=@prefix@/log/mysql/update"
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
	    logopt="$logopt --slow_query_log=1 --slow_query_log_file=@prefix@/log/mysql/slowqueries"

	    # XXX awkward: no -O, a couple of name changes
	    opts="--default-storage-engine=MyISAM --long_query_time=2"
	    if [ $MAINSITE == "0" ]; then
		opts="$opts --key_buffer_size=32M --table_open_cache=128"
		opts="$opts --sort_buffer_size=2M"
		opts="$opts --read_buffer_size=1M --max_connections=250"
	    else
		opts="$opts --key_buffer_size=256M --table_open_cache=256"
		opts="$opts --sort_buffer_size=4M"
		opts="$opts --read_buffer_size=1M --query_cache_size=16M"
		opts="$opts --join_buffer_size=256K --thread_cache_size=4"
		opts="$opts --tmp_table_size=32M --max_heap_table_size=32M"
		opts="$opts --max_connections=350"
	    fi
	fi
else
	safeprog=/usr/local/bin/safe_mysqld
fi

options="--pid-file=/var/db/mysql/mysqld.pid --skip-grant-tables --skip-networking --user=mysql $logopt $opts"
60

61
case "$1" in
62
	start|faststart|quietstart|onestart|forcestart)
63
		if [ -x $safeprog ]; then
64
			if [ "$fbsdvers" = "FreeBSD6" -o $major -eq 5 ]; then
65 66 67 68 69 70 71 72 73 74
			        #
				# mysqld does not properly detach, and so it
				# gets a SIGHUP, which causes it to reload
				# its grant tables, even though it was started
				# with --skip-grant-tables. Breaks everything.
				#
				daemon -f $safeprog $options
			else
				$safeprog $options > /dev/null 2>&1 &
			fi
75
			echo -n ' mysqld'
76 77
		fi
		;;
78
	stop|faststop|quietstop|onestop|forcestop)
79 80 81 82 83 84 85 86 87 88 89 90 91 92
		/usr/bin/killall mysqld > /dev/null 2>&1 && echo -n ' mysqld'
		;;
	*)
		echo ""
		echo "Usage: `basename $0` { start | stop }"
		echo ""
		exit 64
		;;
esac