2.mysql-server.sh.in 3.55 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
    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"
28
    opts="$opts -O max_connections=500"
29
    opts="$opts -O max_allowed_packet=16M"
30
    
31 32
fi

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

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"
39
	    logopt="$logopt --log-bin=@prefix@/log/mysql/update"
40 41
	    logopt="$logopt --slow_query_log=1 --binlog-format=MIXED"
	    logopt="$logopt --slow_query_log_file=@prefix@/log/mysql/slowqueries"
42 43 44

	    # XXX awkward: no -O, a couple of name changes
	    opts="--default-storage-engine=MyISAM --long_query_time=2"
45
	    if [ $MAINSITE == "0" -a $BIGDB == "0" ]; then
46 47 48 49 50 51 52 53 54
		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"
55
		opts="$opts --max_connections=500"
56
		opts="$opts --max_allowed_packet=16M"
57 58
	    fi
	fi
59 60 61 62
	# so that we can dump tables
	if [ $minor -gt 4 ]; then
	    opts="$opts --secure-file-priv="
	fi
63 64 65 66 67
	# so we can start using innodb tables, maybe with compression.
	if [ $minor -gt 5 ]; then
	    opts="$opts --innodb_file_per_table=1 --innodb_file_format=Barracuda"
	    # Backwards compatibility.
	    opts="$opts --lower_case_table_names=0 --log_output=file"
68 69
	    # Strict mode is coming, but we can't handle it.
	    opts="$opts --sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
70
	fi
71 72 73 74 75
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"
76

77
case "$1" in
78
	start|faststart|quietstart|onestart|forcestart)
79
		if [ -x $safeprog ]; then
80
			if [ "$fbsdvers" = "FreeBSD6" -o $major -eq 5 ]; then
81 82 83 84 85 86
			        #
				# 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.
				#
87
				/usr/sbin/daemon -f $safeprog $options
88 89 90
			else
				$safeprog $options > /dev/null 2>&1 &
			fi
91
			echo -n ' mysqld'
92 93
		fi
		;;
94
	stop|faststop|quietstop|onestop|forcestop)
95 96 97 98 99 100 101 102 103 104 105 106 107 108
		/usr/bin/killall mysqld > /dev/null 2>&1 && echo -n ' mysqld'
		;;
	*)
		echo ""
		echo "Usage: `basename $0` { start | stop }"
		echo ""
		exit 64
		;;
esac