Last active
December 19, 2015 22:28
-
-
Save pzskc383/6027220 to your computer and use it in GitHub Desktop.
start() in /etc/init.d/mysql on openrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/mysql/my.cnf: The global mysql configuration file. | |
# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql/files/my.cnf-5.1,v 1.4 2013/01/20 02:40:02 robbat2 Exp $ | |
# The following options will be passed to all MySQL clients | |
[client] | |
#password = your_password | |
port = 3307 | |
socket = /var/run/mysqld/mysqld-rd.sock | |
[mysql] | |
character-sets-dir=/usr/share/mysql/charsets | |
default-character-set=utf8 | |
[mysqladmin] | |
character-sets-dir=/usr/share/mysql/charsets | |
default-character-set=utf8 | |
[mysqlcheck] | |
character-sets-dir=/usr/share/mysql/charsets | |
default-character-set=utf8 | |
[mysqldump] | |
character-sets-dir=/usr/share/mysql/charsets | |
default-character-set=utf8 | |
[mysqlimport] | |
character-sets-dir=/usr/share/mysql/charsets | |
default-character-set=utf8 | |
[mysqlshow] | |
character-sets-dir=/usr/share/mysql/charsets | |
default-character-set=utf8 | |
[myisamchk] | |
character-sets-dir=/usr/share/mysql/charsets | |
[myisampack] | |
character-sets-dir=/usr/share/mysql/charsets | |
# use [safe_mysqld] with mysql-3 | |
[mysqld_safe] | |
err-log = /var/log/mysql/mysql-rd.err | |
# add a section [mysqld-4.1] or [mysqld-5.0] for specific configurations | |
[mysqld] | |
character-set-server = utf8 | |
user = mysql | |
port = 3307 | |
socket = /var/run/mysqld/mysqld-rd.sock | |
pid-file = /var/run/mysqld/mysqld-rd.pid | |
log-error = /var/log/mysql/mysqld-rd.err | |
basedir = /usr | |
datadir = /mnt/ramdisk/mysql | |
skip-external-locking | |
key_buffer = 16M | |
max_allowed_packet = 1M | |
table_open_cache = 64 | |
sort_buffer_size = 512K | |
net_buffer_length = 8K | |
read_buffer_size = 256K | |
read_rnd_buffer_size = 512K | |
myisam_sort_buffer_size = 8M | |
language = /usr/share/mysql/english | |
query_cache_size = 16M | |
thread_cache_size = 4 | |
# security: | |
# using "localhost" in connects uses sockets by default | |
# skip-networking | |
bind-address = 127.0.0.1 | |
#log-bin | |
#server-id = 1 | |
# point the following paths to different dedicated disks | |
tmpdir = /mnt/ramdisk/tmp | |
#log-update = /path-to-dedicated-directory/hostname | |
# you need the debug USE flag enabled to use the following directives, | |
# if needed, uncomment them, start the server and issue | |
# #tail -f /tmp/mysqld.sql /tmp/mysqld.trace | |
# this will show you *exactly* what's happening in your server ;) | |
#log = /tmp/mysqld.sql | |
#gdb | |
#debug = d:t:i:o,/tmp/mysqld.trace | |
#one-thread | |
# uncomment the following directives if you are using BDB tables | |
#bdb_cache_size = 4M | |
#bdb_max_lock = 10000 | |
# the following is the InnoDB configuration | |
# if you wish to disable innodb instead | |
# uncomment just the next line | |
#skip-innodb | |
# | |
# the rest of the innodb config follows: | |
# don't eat too much memory, we're trying to be safe on 64Mb boxes | |
# you might want to bump this up a bit on boxes with more RAM | |
innodb_buffer_pool_size = 16M | |
# this is the default, increase it if you have lots of tables | |
innodb_additional_mem_pool_size = 2M | |
# | |
# i'd like to use /var/lib/mysql/innodb, but that is seen as a database :-( | |
# and upstream wants things to be under /var/lib/mysql/, so that's the route | |
# we have to take for the moment | |
#innodb_data_home_dir = /var/lib/mysql/ | |
#innodb_log_arch_dir = /var/lib/mysql/ | |
#innodb_log_group_home_dir = /var/lib/mysql/ | |
# you may wish to change this size to be more suitable for your system | |
# the max is there to avoid run-away growth on your machine | |
innodb_data_file_path = ibdata1:10M:autoextend:max:128M | |
# we keep this at around 25% of of innodb_buffer_pool_size | |
# sensible values range from 1MB to (1/innodb_log_files_in_group*innodb_buffer_pool_size) | |
innodb_log_file_size = 5M | |
# this is the default, increase it if you have very large transactions going on | |
innodb_log_buffer_size = 8M | |
# this is the default and won't hurt you | |
# you shouldn't need to tweak it | |
innodb_log_files_in_group=2 | |
# see the innodb config docs, the other options are not always safe | |
innodb_flush_log_at_trx_commit = 1 | |
innodb_lock_wait_timeout = 50 | |
innodb_file_per_table | |
[mysqldump] | |
quick | |
max_allowed_packet = 16M | |
[mysql] | |
# uncomment the next directive if you are not familiar with SQL | |
#safe-updates | |
[isamchk] | |
key_buffer = 20M | |
sort_buffer_size = 20M | |
read_buffer = 2M | |
write_buffer = 2M | |
[myisamchk] | |
key_buffer = 20M | |
sort_buffer_size = 20M | |
read_buffer = 2M | |
write_buffer = 2M | |
[mysqlhotcopy] | |
interactive-timeout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start() { | |
[[ -d "/mnt/ramdisk/mysql" ]] && /bin/rm -rf /mnt/ramdisk/mysql | |
if [ ! -d "/mnt/ramdisk/mysql" ] ; then | |
einfo "Creating mysql datadir" | |
/bin/mkdir /mnt/ramdisk/mysql | |
/bin/mkdir /mnt/ramdisk/mysql/mysql | |
/bin/chown -R mysql.mysql /mnt/ramdisk/mysql | |
fi | |
if [ ! -d "/mnt/ramdisk/tmp" ] ; then | |
einfo "Creating mysql tmpdir" | |
/bin/mkdir /mnt/ramdisk/tmp | |
/bin/chmod 777 /mnt/ramdisk/tmp | |
fi | |
/usr/bin/mysql_install_db --user=mysql --datadir=/mnt/ramdisk/mysql >/dev/null | |
# Check for old conf.d variables that mean migration was not yet done. | |
set | egrep -sq '^(mysql_slot_|MYSQL_BLOG_PID_FILE|STOPTIMEOUT)' | |
rc=$? | |
# Yes, MYSQL_INIT_I_KNOW_WHAT_I_AM_DOING is a hidden variable. | |
# It does have a use in testing, as it is possible to build a config file | |
# that works with both the old and new init scripts simulateously. | |
if [ "${rc}" = 0 -a -z "${MYSQL_INIT_I_KNOW_WHAT_I_AM_DOING}" ]; then | |
eerror "You have not updated your conf.d for the new mysql-init-scripts-2 revamp." | |
eerror "Not proceeding because it may be dangerous." | |
return 1 | |
fi | |
# Now we can startup | |
ebegin "Starting $(mysql_svcname)" | |
MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}" | |
if [ ! -r "${MY_CNF}" ] ; then | |
eerror "Cannot read the configuration file \`${MY_CNF}'" | |
return 1 | |
fi | |
# tail -n1 is critical as these we only want the last instance of the option | |
local basedir=$(get_config "${MY_CNF}" basedir | tail -n1) | |
local datadir=$(get_config "${MY_CNF}" datadir | tail -n1) | |
local pidfile=$(get_config "${MY_CNF}" pid-file | tail -n1) | |
local socket=$(get_config "${MY_CNF}" socket | tail -n1) | |
if [ ! -d "${datadir}" ] ; then | |
eerror "MySQL datadir \`${datadir}' is empty or invalid" | |
eerror "Please check your config file \`${MY_CNF}'" | |
return 1 | |
fi | |
if [ ! -d "${datadir}"/mysql ] ; then | |
eerror "You don't appear to have the mysql database installed yet." | |
eerror "Please run /usr/bin/mysql_install_db to have this done..." | |
return 1 | |
fi | |
local piddir="${pidfile%/*}" | |
checkpath -d --owner mysql:mysql --mode 0755 "$piddir" | |
rc=$? | |
if [ $rc -ne 0 ]; then | |
eerror "Directory $piddir for pidfile does not exist and cannot be created" | |
return 1 | |
fi | |
local startup_timeout=${STARTUP_TIMEOUT:-900} | |
local startup_early_timeout=${STARTUP_EARLY_TIMEOUT:-1000} | |
local tmpnice="${NICE:+"--nicelevel "}${NICE}" | |
local tmpionice="${IONICE:+"--ionice "}${IONICE}" | |
start-stop-daemon \ | |
${DEBUG:+"--verbose"} \ | |
--start \ | |
--exec "${basedir}"/sbin/mysqld \ | |
--pidfile "${pidfile}" \ | |
--background \ | |
--wait ${startup_early_timeout} \ | |
${tmpnice} \ | |
${tmpionice} \ | |
-- --defaults-file="${MY_CNF}" ${MY_ARGS} | |
local ret=$? | |
if [ ${ret} -ne 0 ] ; then | |
eend ${ret} | |
return ${ret} | |
fi | |
ewaitfile ${startup_timeout} "${socket}" | |
eend $? || return 1 | |
save_options pidfile "${pidfile}" | |
save_options basedir "${basedir}" | |
einfo "Setting up users" | |
OLDIFS=$IFS | |
IFS=, | |
for u in `grep mysql /etc/group |cut -d: -f4`; do | |
echo "GRANT ALL PRIVILEGES ON *.* TO '$u'@'localhost' WITH GRANT OPTION" | mysql -S /var/run/mysqld/mysqld-rd.sock; | |
done | |
IFS=$OLDIFS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment