View | Details | Raw Unified | Return to bug 178726
Collapse All | Expand All

(-)files/mysql-server.in (-17 / +74 lines)
Lines 1-26 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
#
2
3
# $FreeBSD$
3
# $FreeBSD$
4
#
4
#
5
6
# PROVIDE: mysql
5
# PROVIDE: mysql
7
# REQUIRE: LOGIN
6
# REQUIRE: LOGIN
8
# KEYWORD: shutdown
7
# KEYWORD: shutdown
9
10
#
8
#
11
# Add the following line to /etc/rc.conf to enable mysql:
9
# Add the following line to /etc/rc.conf to enable mysql:
12
# mysql_enable (bool):	Set to "NO" by default.
10
# mysql_(instance_)?enable (bool):	Set to "NO" by default.
13
#			Set it to "YES" to enable MySQL.
11
#			Set it to "YES" to enable MySQL.
14
# mysql_limits (bool):	Set to "NO" by default.
12
# mysql_(instance_)?limits (bool):	Set to "NO" by default.
15
#			Set it to yes to run `limits -e -U mysql`
13
#			Set it to yes to run `limits -e -U mysql`
16
#			just before mysql starts.
14
#			just before mysql starts.
17
# mysql_dbdir (str):	Default to "/var/db/mysql"
15
# mysql_(instance_)?dbdir (str):	Default to "/var/db/mysql"
18
#			Base database directory.
16
#			Base database directory.
19
# mysql_pidfile (str):	Custum PID file path and name.
17
# mysql_(instance_)?args (str):	Custom additional arguments to be passed
18
#			to mysqld_safe (default empty).
19
# mysql_(instance_)?pidfile (str): Custum PID file path and name.
20
#			Default to "${mysql_dbdir}/${hostname}.pid".
20
#			Default to "${mysql_dbdir}/${hostname}.pid".
21
# mysql_args (str):	Custom additional arguments to be passed
21
# mysql_(instance_)?user (str): User to run mysqld as
22
#			to mysqld_safe (default empty).
22
#			Default to "mysql" created by the port
23
#
23
# mysql_(instance_)?optfile (str): Server-specific option file.
24
#			Default to "${mysql_dbdir}/my.cnf".
25
# mysql_instances (str): Set to "" by default. 
26
#			If defined, list of instances to enable
24
27
25
. /etc/rc.subr
28
. /etc/rc.subr
26
29
Lines 31-53 Link Here
31
34
32
: ${mysql_enable="NO"}
35
: ${mysql_enable="NO"}
33
: ${mysql_limits="NO"}
36
: ${mysql_limits="NO"}
37
: ${mysql_user="mysql"}
38
: ${mysql_limits_args="-e -U $mysql_user"}
34
: ${mysql_dbdir="/var/db/mysql"}
39
: ${mysql_dbdir="/var/db/mysql"}
40
: ${mysql_optfile="${mysql_dbdir}/my.cnf"}
35
41
36
mysql_user="mysql"
37
mysql_limits_args="-e -U ${mysql_user}"
38
pidfile=${mysql_pidfile:-"${mysql_dbdir}/`/bin/hostname`.pid"}
39
command="/usr/sbin/daemon"
42
command="/usr/sbin/daemon"
40
command_args="-c -f %%PREFIX%%/bin/mysqld_safe --defaults-extra-file=${mysql_dbdir}/my.cnf --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} ${mysql_args}"
41
procname="%%PREFIX%%/libexec/mysqld"
43
procname="%%PREFIX%%/libexec/mysqld"
42
start_precmd="${name}_prestart"
44
start_precmd="${name}_prestart"
43
start_postcmd="${name}_poststart"
45
start_postcmd="${name}_poststart"
46
47
if [ -n "$2" ]; then
48
	instance="$2"
49
	load_rc_config ${name}_${instance}
50
	case "$mysql_instances" in
51
	"$2 "*|*" $2 "*|*" $2"|"$2")
52
		eval mysql_args="\${mysql_${instance}_args:-\"${mysql_args}\"}"
53
		eval mysql_dbdir="\${mysql_${instance}_dbdir:-\"/var/db/mysql_${instance}\"}"
54
		eval mysql_limits="\${mysql_${instance}_limits:-\"${mysql_limits}\"}"
55
		eval mysql_user="\${mysql_${instance}_user:-\"${mysql_user}\"}"
56
		eval mysql_limits_args="\${mysql_${instance}_limits_args:-\"-e -U $mysql_user\"}"
57
		eval mysql_optfile="\${mysql_${instance}_optfile:-\"${mysql_dbdir}/my.cnf\"}"
58
		eval mysql_pidfile="\${mysql_${instance}_pidfile:-\"${mysql_dbdir}/`/bin/hostname`.pid\"}"
59
	;;
60
	*)
61
		err 1 "$2 not found in mysql_instances" ;;
62
	esac
63
else
64
	if [ -n "${mysql_instances}" -a -n "$1" ]; then
65
		for instance in ${mysql_instances}; do
66
			eval _enable="\${mysql_${instance}_enable}"
67
			case "${_enable:-${mysql_enable}}" in
68
			[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
69
				continue
70
			;;
71
			[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
72
			;;
73
			*)
74
				if [ -z "$_enable" ]; then
75
					_var=mysql_enable
76
				else
77
					_var=mysql_${instance}_enable
78
				fi
79
				warn "Bad value" \
80
					"'${_enable:-${mysql_enable}}'" \
81
					"for ${_var}. " \
82
					"Instance ${instance} skipped."
83
				continue
84
			;;
85
			esac
86
			echo "===> mysql instance: ${instance}"
87
			if %%PREFIX%%/etc/rc.d/mysql-server $1 ${instance}; then
88
				success="${instance} ${success}"
89
			else
90
				failed="${instance} (${retcode}) ${failed}"
91
			fi
92
		done
93
		exit 0
94
	else
95
		mysql_pidfile=${mysql_pidfile:-"${mysql_dbdir}/`/bin/hostname`.pid"}
96
	fi
97
fi
98
99
pidfile=$mysql_pidfile
44
mysql_install_db="%%PREFIX%%/bin/mysql_install_db"
100
mysql_install_db="%%PREFIX%%/bin/mysql_install_db"
45
mysql_install_db_args="--basedir=%%PREFIX%% --datadir=${mysql_dbdir} --force"
101
mysql_install_db_args="--basedir=%%PREFIX%% --datadir=${mysql_dbdir} --force"
102
command_args="-c -f %%PREFIX%%/bin/mysqld_safe --defaults-extra-file=${mysql_optfile} --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} ${mysql_args}"
46
103
47
mysql_create_auth_tables()
104
mysql_create_auth_tables()
48
{
105
{
49
	eval $mysql_install_db $mysql_install_db_args >/dev/null 2>/dev/null
106
	eval $mysql_install_db $mysql_install_db_args
50
        [ $? -eq 0 ] && chown -R ${mysql_user}:${mysql_user} ${mysql_dbdir}
107
        [ $? -eq 0 ] && chown -R ${mysql_user}:$(id -gn $mysql_user) ${mysql_dbdir}
51
}
108
}
52
109
53
mysql_prestart()
110
mysql_prestart()
Lines 56-62 Link Here
56
		mysql_create_auth_tables || return 1
113
		mysql_create_auth_tables || return 1
57
	fi
114
	fi
58
	if checkyesno mysql_limits; then
115
	if checkyesno mysql_limits; then
59
		eval `/usr/bin/limits ${mysql_limits_args}` 2>/dev/null
116
		eval `/usr/bin/limits ${mysql_limits_args:-"-e -U $mysql_user"}` 2>/dev/null
60
	else
117
	else
61
		return 0
118
		return 0
62
	fi
119
	fi

Return to bug 178726