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