Changeset View
Changeset View
Standalone View
Standalone View
databases/mariadb105-server/files/mysql-server.in
#!/bin/sh | #!/bin/sh | ||||
# PROVIDE: mysql | # PROVIDE: mysql | ||||
# REQUIRE: LOGIN | # REQUIRE: LOGIN | ||||
# KEYWORD: shutdown | # KEYWORD: shutdown | ||||
# | # | ||||
# Add the following line to /etc/rc.conf to enable mysql: | # Add the following line to /etc/rc.conf to enable mysql: | ||||
# mysql_(instance_)?enable (bool): Set to "NO" by default. | # mysql_(instance_)?enable (bool): Set to "NO" by default. | ||||
# Set it to "YES" to enable MySQL. | # 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): Default to "%%MARIADB_DBDIR%%" | # mysql_(instance_)?dbdir (str): Default to "%%MARIADB_DBDIR%%" | ||||
# Base database directory. | # Base database directory. | ||||
# mysql_(instance_)?args (str): Custom additional arguments to be passed | # mysql_(instance_)?args (str): Custom additional arguments to be passed | ||||
# to mysqld_safe (default empty). | # to mysqld_safe (default empty). | ||||
# mysql_(instance_)?pidfile (str): Custum PID file path and name. | # mysql_(instance_)?pidfile (str): Custum PID file path and name. | ||||
# Default to "${mysql_dbdir}/${hostname}.pid". | # Default to "${mysql_dbdir}/${hostname}.pid". | ||||
# mysql_(instance_)?user (str): User to run mysqld as | # mysql_(instance_)?user (str): User to run mysqld as | ||||
# Default to "%%MARIADB_USER%%" created by the port | # Default to "%%MARIADB_USER%%" created by the port | ||||
# mysql_(instance_)?optfile (str): Server-specific option file. | # mysql_(instance_)?optfile (str): Server-specific option file. | ||||
# Default to "${mysql_dbdir}/my.cnf". | # Default to "${mysql_dbdir}/my.cnf". | ||||
# mysql_(instance)?rundir (str): Default to "%%MARIADB_RUNDIR%%" | # mysql_(instance)?rundir (str): Default to "%%MARIADB_RUNDIR%%" | ||||
# mysql_instances (str): Set to "" by default. | # mysql_instances (str): Set to "" by default. | ||||
# If defined, list of instances to enable | # If defined, list of instances to enable | ||||
. /etc/rc.subr | . /etc/rc.subr | ||||
name="mysql" | name="mysql" | ||||
rcvar=mysql_enable | rcvar=mysql_enable | ||||
load_rc_config $name | load_rc_config $name | ||||
: ${mysql_enable="NO"} | : ${mysql_enable="NO"} | ||||
%%LEGACY_LIMITS%%: ${mysql_limits="NO"} | |||||
: ${mysql_user="%%MARIADB_USER%%"} | : ${mysql_user="%%MARIADB_USER%%"} | ||||
%%LEGACY_LIMITS%%mysql_limits_args="-e -U ${mysql_user}" | |||||
: ${mysql_dbdir="%%MARIADB_DBDIR%%"} | : ${mysql_dbdir="%%MARIADB_DBDIR%%"} | ||||
: ${mysql_optfile="%%ETCDIR%%/my.cnf"} | : ${mysql_optfile="%%ETCDIR%%/my.cnf"} | ||||
: ${mysql_rundir="%%MARIADB_RUNDIR%%"} | : ${mysql_rundir="%%MARIADB_RUNDIR%%"} | ||||
command="/usr/sbin/daemon" | command="/usr/sbin/daemon" | ||||
procname="%%PREFIX%%/libexec/mariadbd" | procname="%%PREFIX%%/libexec/mariadbd" | ||||
start_precmd="${name}_prestart" | start_precmd="${name}_prestart" | ||||
start_postcmd="${name}_poststart" | start_postcmd="${name}_poststart" | ||||
if [ -n "$2" ]; then | if [ -n "$2" ]; then | ||||
instance="$2" | instance="$2" | ||||
load_rc_config ${name}_${instance} | load_rc_config ${name}_${instance} | ||||
case "$mysql_instances" in | case "$mysql_instances" in | ||||
"$2 "*|*" $2 "*|*" $2"|"$2") | "$2 "*|*" $2 "*|*" $2"|"$2") | ||||
eval mysql_args="\${mysql_${instance}_args:-\"${mysql_args}\"}" | eval mysql_args="\${mysql_${instance}_args:-\"${mysql_args}\"}" | ||||
eval mysql_dbdir="\${mysql_${instance}_dbdir:-\"%%MARIADB_DBDIR%%_${instance}\"}" | eval mysql_dbdir="\${mysql_${instance}_dbdir:-\"%%MARIADB_DBDIR%%_${instance}\"}" | ||||
%%LEGACY_LIMITS%%eval mysql_limits="\${mysql_${instance}_limits:-\"${mysql_limits}\"}" | |||||
eval mysql_user="\${mysql_${instance}_user:-\"${mysql_user}\"}" | 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:-\"%%MARIADB_RUNDIR%%_${instance}/%%MARIADB_SOCK%%\"}" | eval mysql_socket="\${mysql_${instance}_socket:-\"%%MARIADB_RUNDIR%%_${instance}/%%MARIADB_SOCK%%\"}" | ||||
eval mysql_optfile="\${mysql_${instance}_optfile:-\"%%ETCDIR%%_${instance}/my.cnf\"}" | eval mysql_optfile="\${mysql_${instance}_optfile:-\"%%ETCDIR%%_${instance}/my.cnf\"}" | ||||
eval mysql_pidfile="\${mysql_${instance}_pidfile:-\"%%MARIADB_RUNDIR%%_${instance}/mysqld.pid\"}" | eval mysql_pidfile="\${mysql_${instance}_pidfile:-\"%%MARIADB_RUNDIR%%_${instance}/mysqld.pid\"}" | ||||
;; | ;; | ||||
*) | *) | ||||
err 1 "$2 not found in mysql_instances" ;; | err 1 "$2 not found in mysql_instances" ;; | ||||
esac | esac | ||||
else | else | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | mysql_prestart() | ||||
if [ ! -d "${mysql_dbdir}/mysql/." ]; then | if [ ! -d "${mysql_dbdir}/mysql/." ]; then | ||||
mysql_create_auth_tables || return 1 | mysql_create_auth_tables || return 1 | ||||
fi | fi | ||||
mysql_group="`/usr/bin/id -gn ${mysql_user}`" | mysql_group="`/usr/bin/id -gn ${mysql_user}`" | ||||
[ "${mysql_socket}" = "" ] && mysql_rundir="%%MARIADB_RUNDIR%%" || mysql_rundir="`/usr/bin/dirname ${mysql_socket}`" | [ "${mysql_socket}" = "" ] && mysql_rundir="%%MARIADB_RUNDIR%%" || mysql_rundir="`/usr/bin/dirname ${mysql_socket}`" | ||||
if [ ! -d "${mysql_rundir}" ]; then | if [ ! -d "${mysql_rundir}" ]; then | ||||
install -d -o ${mysql_user} -g ${mysql_group} "${mysql_rundir}" | install -d -o ${mysql_user} -g ${mysql_group} "${mysql_rundir}" | ||||
fi | fi | ||||
%%LEGACY_LIMITS%% if checkyesno mysql_limits; then | return 0 | ||||
%%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 | |||||
if [ ! -d "${mysql_rundir}" ]; then | if [ ! -d "${mysql_rundir}" ]; then | ||||
install -d -u${mysql_user} -g$(id -gn $mysql_user) -m755 ${mysql_rundir} | install -d -u${mysql_user} -g$(id -gn $mysql_user) -m755 ${mysql_rundir} | ||||
fi | fi | ||||
} | } | ||||
mysql_poststart() | mysql_poststart() | ||||
{ | { | ||||
local timeout=15 | local timeout=15 | ||||
while [ ! -f "${pidfile}" -a ${timeout} -gt 0 ]; do | while [ ! -f "${pidfile}" -a ${timeout} -gt 0 ]; do | ||||
timeout=$(( timeout - 1 )) | timeout=$(( timeout - 1 )) | ||||
sleep 1 | sleep 1 | ||||
done | done | ||||
return 0 | return 0 | ||||
} | } | ||||
run_rc_command "$1" | run_rc_command "$1" |