Skip to content

Instantly share code, notes, and snippets.

@yellowback
Created June 26, 2013 06:56
Show Gist options
  • Save yellowback/5865302 to your computer and use it in GitHub Desktop.
Save yellowback/5865302 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# $NetBSD: mysqld.sh,v 1.1.1.1 2011/04/25 21:12:15 adam Exp $
#
# PROVIDE: mysqld
# REQUIRE: DAEMON LOGIN mountall
# KEYWORD: shutdown
#
# You will need to set some variables in /etc/rc.conf to start MySQL:
#
# mysqld=YES
#
# The following variables are optional:
#
# mysqld_user="mysql" # user to run mysqld as
# mysqld_datadir="/path/to/home" # path to MySQL database directory
#
if [ -f /etc/rc.subr ]; then
. /etc/rc.subr
fi
name="mysqld"
rcvar=${name}
command="/usr/local/mysql/bin/mysqld_safe"
procname="/usr/local/mysql/bin/${name}"
: ${mysqld_user:=mysql}
: ${mysqld_group:=mysql}
: ${mysqld_datadir:=/var/mysql}
extra_commands="initdb"
initdb_cmd="mysqld_initdb"
start_precmd="mysqld_precmd"
start_cmd="mysqld_start"
mysqld_precmd()
{
if [ ! -d ${mysqld_datadir}/mysql ]; then
${initdb_cmd}
fi
}
mysqld_initdb()
{
initdb="/usr/local/mysql/scripts/mysql_install_db"
if [ ! -x ${initdb} ]; then
return 1
fi
if [ -f ${mysqld_datadir}/mysql/host.frm ]; then
/bin/echo "The MySQL database has already been initialized."
/bin/echo "Skipping database initialization."
else
/bin/echo "Initializing MySQL database system tables."
${initdb} --force --user=${mysqld_user} --basedir=/usr/local/mysql \
--datadir=${mysqld_datadir} || return 1
if [ -d ${mysqld_datadir} ]; then
/usr/sbin/chown -R ${mysqld_user}:${mysqld_group} \
${mysqld_datadir}
fi
fi
}
mysqld_start()
{
for f in $required_files; do
if [ ! -r "$f" ]; then
/bin/echo 1>&2 "$0: WARNING: $f is not readable"
if [ -z $rc_force ]; then
return 1
fi
fi
done
/bin/echo "Starting ${name}."
ulimit -n 4096
cd /usr/local/mysql
${command} --user=${mysqld_user} --datadir=${mysqld_datadir} \
--pid-file=${pidfile} ${mysqld_flags} \
${thread_flags} &
}
if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then
load_rc_config $name
pidfile="${mysqld_datadir}/`/bin/hostname`.pid"
run_rc_command "$1"
else
if [ -f /etc/rc.conf ]; then
. /etc/rc.conf
fi
pidfile="${mysqld_datadir}/`/bin/hostname`.pid"
case "$1" in
initdb)
eval ${initdb_cmd}
;;
stop)
if [ -r "${pidfile}" ]; then
/bin/echo "Stopping ${name}."
kill `/bin/cat ${pidfile}`
fi
;;
*)
eval ${start_precmd}
eval ${start_cmd}
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment