2013-01-10 17:35:12 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# This script creates the mysql data directory during first service start.
|
|
|
|
# In subsequent starts, it does nothing much.
|
|
|
|
|
2014-07-24 08:00:33 +00:00
|
|
|
source "`dirname ${BASH_SOURCE[0]}`/mysql-scripts-common"
|
2013-01-10 17:35:12 +00:00
|
|
|
|
2014-07-23 13:26:28 +00:00
|
|
|
# If two args given first is user, second is group
|
|
|
|
# otherwise the arg is the systemd service file
|
|
|
|
if [ "$#" -eq 2 ]
|
2013-01-10 17:35:12 +00:00
|
|
|
then
|
2014-07-23 13:26:28 +00:00
|
|
|
myuser="$1"
|
|
|
|
mygroup="$2"
|
|
|
|
else
|
|
|
|
# Absorb configuration settings from the specified systemd service file,
|
2014-07-24 08:00:33 +00:00
|
|
|
# or the default service if not specified
|
2014-07-23 13:26:28 +00:00
|
|
|
SERVICE_NAME="$1"
|
|
|
|
if [ x"$SERVICE_NAME" = x ]
|
|
|
|
then
|
|
|
|
SERVICE_NAME=@DAEMON_NAME@.service
|
|
|
|
fi
|
2013-01-10 17:35:12 +00:00
|
|
|
|
2014-07-23 13:26:28 +00:00
|
|
|
myuser=`systemctl show -p User "${SERVICE_NAME}" |
|
|
|
|
sed 's/^User=//'`
|
|
|
|
if [ x"$myuser" = x ]
|
|
|
|
then
|
|
|
|
myuser=mysql
|
|
|
|
fi
|
2013-01-10 17:35:12 +00:00
|
|
|
|
2014-07-23 13:26:28 +00:00
|
|
|
mygroup=`systemctl show -p Group "${SERVICE_NAME}" |
|
|
|
|
sed 's/^Group=//'`
|
|
|
|
if [ x"$mygroup" = x ]
|
|
|
|
then
|
|
|
|
mygroup=mysql
|
|
|
|
fi
|
2013-01-10 17:35:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set up the errlogfile with appropriate permissions
|
|
|
|
touch "$errlogfile"
|
2014-07-18 07:52:36 +00:00
|
|
|
ret=$?
|
|
|
|
# Provide some advice if the log file cannot be touched
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
errlogdir=$(dirname $errlogfile)
|
|
|
|
if ! [ -d "$errlogdir" ] ; then
|
|
|
|
echo "The directory $errlogdir does not exist."
|
|
|
|
elif [ -f "$errlogfile" ] ; then
|
|
|
|
echo "The log file $errlogfile cannot be touched, please, fix its permissions."
|
|
|
|
else
|
|
|
|
echo "The log file $errlogfile could not be created."
|
|
|
|
fi
|
|
|
|
echo "The daemon will be run under $myuser:$mygroup"
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-01-10 17:35:12 +00:00
|
|
|
chown "$myuser:$mygroup" "$errlogfile"
|
|
|
|
chmod 0640 "$errlogfile"
|
|
|
|
[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
|
|
|
|
|
|
|
|
# Make the data directory
|
|
|
|
if [ ! -d "$datadir/mysql" ] ; then
|
|
|
|
# First, make sure $datadir is there with correct permissions
|
|
|
|
# (note: if it's not, and we're not root, this'll fail ...)
|
|
|
|
if [ ! -e "$datadir" -a ! -h "$datadir" ]
|
|
|
|
then
|
|
|
|
mkdir -p "$datadir" || exit 1
|
|
|
|
fi
|
|
|
|
chown "$myuser:$mygroup" "$datadir"
|
|
|
|
chmod 0755 "$datadir"
|
|
|
|
[ -x /sbin/restorecon ] && /sbin/restorecon "$datadir"
|
|
|
|
|
|
|
|
# Now create the database
|
2014-07-24 08:00:33 +00:00
|
|
|
echo "Initializing @NICE_PROJECT_NAME@ database"
|
2014-08-05 12:20:26 +00:00
|
|
|
@bindir@/mysql_install_db --rpm --datadir="$datadir" --user="$myuser"
|
2013-01-10 17:35:12 +00:00
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
2014-07-24 08:00:33 +00:00
|
|
|
echo "Initialization of @NICE_PROJECT_NAME@ database failed." >&2
|
2014-07-21 12:41:04 +00:00
|
|
|
echo "Perhaps @sysconfdir@/my.cnf is misconfigured." >&2
|
2013-01-10 17:35:12 +00:00
|
|
|
# Clean up any partially-created database files
|
|
|
|
if [ ! -e "$datadir/mysql/user.frm" ] ; then
|
|
|
|
rm -rf "$datadir"/*
|
|
|
|
fi
|
|
|
|
exit $ret
|
|
|
|
fi
|
2014-09-29 12:34:41 +00:00
|
|
|
# upgrade does not need to be run on a fresh datadir
|
|
|
|
echo "@MYSQL_VERSION_ID@" >"$datadir/mysql_upgrade_info"
|
2013-01-10 17:35:12 +00:00
|
|
|
# In case we're running as root, make sure files are owned properly
|
|
|
|
chown -R "$myuser:$mygroup" "$datadir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|