3.3 Startup script
On might use the startup script provided by mysql sources
in support-files/ and named mysql.server.sh or
the Beyond Linux® From Scratch 11.1 MySql provided script. The latter looks
like more compatible with our installation. Anyway here is
a slightly modified version of the latter fully compatible
with our installation instructions
(cf. 3.2 :)
#!/bin/sh
### mysql ---
##
## Project: init.d 11.1
## In: Rc.d 11.1
## In: Etc 11.1
##
## Copyright (C) 2020 -- 2023 Pierre L. Nageoire
##
## Author: Pierre L. Nageoire <devel@pollock-nageoire.net>
## X-RCS: $Id: mysql.tex 307 2023-12-18 05:05:09Z devel $
##
###############################################################
##
## This program is free software; you can redistribute it
## and/or modify it under the terms of the GNU General Public
## License as published by the Free Software Foundation;
## either version 2, or (at your option) any later version.
##
## This program is distributed in the hope that it will be
## useful, but WITHOUT ANY WARRANTY; without even the implied
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE.
##
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public
## License along with this program; see the file COPYING.
##
## If not, write to the Free Software Foundation, Inc., 51
## Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
###############################################################
##
### Commentary:
##
## Executed in the chrooted environment.
##
### Code:
##
########################################################################
# Begin /etc/init.d/mysql
#
# Description : Start MysSQL Server
#
# Author : Bruce Dubbs - bdubbs@linuxfromscratch.org
#
# Version : LFS 7.0
#
########################################################################
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $network
# Should-Start: $remote_fs
# Required-Stop: $network
# Should-Stop: $remote_fs
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Starts MySQL server.
# Description: Starts MySQL server.
# X-LFS-Provided-By: BLFS / LFS 7.0
### END INIT INFO
. /lib/lsb/init-functions
#$LastChangedBy: igor $
#$Date: 2014-10-11 03:51:32 -0500 (Sat, 11 Oct 2014) $
#
# PLN Mon Jul 6 10:25:05 2020
#
# Beware, /var/run is a tmpfs directory hence should be created each
# time system is restarted.
#
MYSQL_RUNDIR=/var/run/mysql
#
# Save the pid in this directory as well !!!
#
# You Cannot decide arbitrary where to pid; server itself
# dicides. But you should know to determine if server is
# running running or not.
#
PIDFILE=/srv/mysql/`/bin/hostname`.pid
MYSQL_LOGDIR=/var/log/mysql
MYSQL_LOGFILE=${MYSQL_LOGDIR}/error.log
case "$1" in
start)
log_info_msg "Starting MySQL daemon..."
##
## Make sure the mysql user can create a socket and a log
## file. Moreover mysqld .sock should be accessible by
## other users like httpd for instance; for WordPress
## transactions in particular. It seems that it is not
## enough to add mysql group to httpd user.
##
for MYSQL_DIR in ${MYSQL_RUNDIR} ${MYSQL_LOGDIR}
do
mkdir -pv ${MYSQL_DIR}
chown -v mysql:mysql ${MYSQL_DIR}
done
chmod -v 750 ${MYSQL_LOGDIR}
chmod -v 755 ${MYSQL_RUNDIR}
touch ${MYSQL_LOGFILE}
chown -v mysql:mysql ${MYSQL_LOGFILE}
if [ -f "$PIDFILE" ]; then
if /bin/ps -e | grep `cat $PIDFILE` | grep mysqld >/dev/null ; then
log_warning_msg "\n mysqld already running!"
exit 0
else
rm -f "$PIDFILE"
if [ -f "$PIDFILE" ]; then
log_failure_msg2
exit 1
fi
fi
fi
/usr/bin/mysqld_safe --user=mysql \
--log-error=${MYSQL_LOG_FILE} &
evaluate_retval
;;
stop)
log_info_msg "Stopping MySQL daemon..."
killproc -p ${PIDFILE} /usr/sbin/mysqld
evaluate_retval
;;
reload)
log_info_msg "Reloading MySQL ..."
killproc -p ${PIDFILE} /usr/sbin/mysqld -HUP
evaluate_retval
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
statusproc /usr/sbin/mysqld
;;
*)
echo "Usage: $0 {start|stop|reload|restart|status}"
exit 1
;;
esac
# End /etc/init.d/mysql