#742900#5
Date:
2014-03-28 19:20:04 UTC
From:
To:
Implementation of systemd is imminent, yet after days of research I can
not find a mysqld.service file that actually works in Debian.  I've
searched and searched, asked on mailing lists, and asked in IRC on
#debian, #systemd, and #mysql.

Nobody knows, or at least nobody helps.  There isn't even a
mysqld.service file in Sid's mysql-server package.

I can't use the sysv-dependent systemd service as I have another service
which depends on mysql (mythtv-backend), and it simply does not work
with the kludge.

This is a showstopper for me, and probably others.

#742900#10
Date:
2014-03-28 20:25:39 UTC
From:
To:
Excerpts from merc1984's message of 2014-03-28 12:20:04 -0700:

Hi merc. mythtv-backend shouldn't "depend" on the ordering of local
MySQL startup anyway. What if you boot your external MySQL server at
the same time as mythtv-backend? YOu can't really control the sequence
of that ever.

I suggest making mythtv-backend poll like this:

while !mysqladmin ping --host=${mysqlserver} --user=${mysqluser} --password=${mysqlpadd} ; do
  echo "MySQL not ready yet."
  sleep 5
done

Also consider filing a bug in mythtv-backend's upstream code, as it
should be able to poll at startup and reconnect on errors as well.

As for a working systemd unit file.. perhaps we can crib from Fedora?

#742900#15
Date:
2014-03-28 21:16:52 UTC
From:
To:
Doesn't the mythtv-backend package have an "/etc/init.d/" script?

Also, you can't have looked very hard. (You'd have to adapt the
"/usr/libexec/*" files for Debian.)


mysqld.service from Fedora 18 (without comments):

[Unit]
Description=MySQL database server
After=syslog.target
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql
ExecStartPre=/usr/libexec/mysqld-prepare-db-dir %n
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID
TimeoutSec=300
PrivateTmp=true

[Install]
WantedBy=multi-user.target


mariadb.service from Fedora 20 (without comments):

[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql
ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
TimeoutSec=300
PrivateTmp=true

[Install]
WantedBy=multi-user.target

#742900#20
Date:
2014-03-28 22:17:22 UTC
From:
To:
Can't.  My mythbackend.service also must depend on a device to come
ready after its firmware is loaded.  And this requires that it be a
systemd service.

Of course Myth should depend on MySQL first starting.  In my
mythbackend.service I have Requires=mysqld.service and
After=mysqld.service, so it will wait for mysql to start, no polling
needed.  And polling is inferior to having systemd handle the
dependencies.

But in order for systemd to handle it, there must also be a
mysqld.service service, and nothing I've tried has worked.  I've tried
to use Fed's mysql.service and Arch's mysql.service, but each has quite
a different structure than Debian, and I could not get either to work no
matter how much fiddling.  Finally after days of struggle I gave up and
filed this bug.

#742900#25
Date:
2014-03-28 23:16:32 UTC
From:
To:
While it would be great to have a native systemd service file for mysql,
this information is plain incorrect:

You can certainly depend within a .service file on a sysv init script

Since the SysV init script is named /etc/init.d/mysql, you'd have to use
something like


[Unit]
Description=my awesome daemon
After=mysql.service


If mysql-service ships a native systemd .service file, it should ensure
to align the names, i.e. use mysql.service and /etc/init.d/mysql

If the mysql maintainer need more information, please poke us (the
pkg-systemd-maintainers) at
pkg-systemd-maintainers@lists.alioth.debian.org

#742900#30
Date:
2014-03-28 23:17:41 UTC
From:
To:
Excerpts from merc1984's message of 2014-03-28 15:17:22 -0700:

I respectfully disagree. Polling handles cross-machine dependencies
whereas systemd dependency handling is limited to ordering of startup on
a single machine. The only advantage systemd ordering gives us is faster
boot.

Since you're likely only interesting in single machine, and boot time
matters to you, I understand that you would like systemd support in
mysqld. But neither method is "superior" or "inferior".

Understood, and we should definitely have a mysqld service file. I would
suggest you work out those differences and write one yourself, or find a
systemd interested person (I am not one) to help with it.

#742900#35
Date:
2014-03-28 23:42:58 UTC
From:
To:
That's very nice in theory, but I am telling you in practice it does not
work.  That's why I'm having to go to all this trouble.

#742900#40
Date:
2014-03-28 23:46:35 UTC
From:
To:
I, as I say, have given this my best shot and have failed.  That is why
I am asking here.

As systemd is imminent in Debian, I should have thought the MySQL
maintainer would have given this just a little bit of thought.  Is he
present?

#742900#45
Date:
2014-03-29 07:16:29 UTC
From:
To:
Excerpts from merc1984's message of 2014-03-28 16:46:35 -0700:

There isn't one. We are a loose team. I have very little time to spend
on MySQL maintenance these days.

#742900#50
Date:
2014-03-31 17:47:34 UTC
From:
To:
Hi merc,

merc1984@f-m.fm writes:
“It does not work” is not a proper description of a problem. As you seem
to be convinced that this is broken, may I ask you to file a bug report
against systemd? That will include more information (state dump) to
start with. Also, please increase the log level to “debug” — see
https://wiki.debian.org/systemd#Debugging — and provide the output of
journalctl -b.

Thanks.

#742900#55
Date:
2014-03-31 17:57:32 UTC
From:
To:
Excerpts from Michael Stapelberg's message of 2014-03-31 10:47:34 -0700:

It is more likely that it is a problem with the mysql sysvinit script
and mysqld itself. What is probably wrong is that mysqld is daemonizing
and returning control to the terminal before it is _actually_ ready.

Note that in Ubuntu the upstart job for mysqld runs it in the foreground,
and the post-start _polls mysqld_ so that anything that wants to be
'start on started mysqld' will have a working mysqld.

Still, I would appreciate the "it doesn't work" full description too.

#742900#60
Date:
2014-03-31 20:52:37 UTC
From:
To:
Unfortunately the problem is not with systemd.  It is with Debian for
not having a .service file suited to its structure.  I've tried to adapt
the Arch and Fedora .service files, but can't make them work.  The
failures are diverse, and depend on the nature of differing  adaptations
I've made in them for Debian.  The solution is not to describe how my
attempts fail six ways from Sunday.  The solution is to specify an
official file which actually works in Debian.

The primary problem with my .service file is that it simply does not
start mysqld on boot.  I've concentrated on adapting the Fedora file, as
it's more likely to be credible, given that it's used in RHEL.

My mysql.service:
---------------------------------------------------------------------------------------
# Adapted  from Fedora

# For more info about custom unit files, see systemd.unit(5) or
#
http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# For example, if you want to increase mysql's open-files-limit to
10000,
# you need to increase systemd's LimitNOFILE setting, so create a file
named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
#       [Service]
#       LimitNOFILE=10000

# Note: /usr/lib/... is recommended in the .include line though /lib/...
# still works.
# Don't forget to reload systemd daemon after you change unit
configuration:
# root> systemctl --system daemon-reload

[Unit]
Description=MySQL database server
After=syslog.target network.target

[Service]
Type=simple
User=mysql
Group=mysql

ExecStartPre=/usr/local/bin/mysql-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux
alarms,
# per bug #547485
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/local/bin/mysql-wait-ready $MAINPID

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

# Security
PrivateTmp=yes
#InaccessibleDirectories=/boot /.config /home/backups /home/bill
/home/sleeper /lib32 /media /mnt /opt /proc /root /srv /sys
#ReadOnlyDirectories=/bin /etc /sbin /usr
#CapabilityBoundingSet=~CAP_SYS_PTRACE
#DeviceAllow=/dev/null rw
#NoNewPrivileges=yes

[Install]
WantedBy=multi-user.target

systemctl status mysqld
---------------------------------------------------------------------------------------
# systemctl status mysqld
mysqld.service - MySQL database server
   Loaded: loaded (/usr/local/lib/systemd/system/mysqld.service;
   enabled)
   Active: failed (Result: exit-code) since Mon 2014-03-31 12:39:46 PDT;
   1h 3min ago
  Process: 2341 ExecStartPost=/usr/local/bin/mysql-wait-ready $MAINPID
  (code=exited, status=1/FAILURE)
  Process: 2340 ExecStart=/usr/bin/mysqld_safe --basedir=/usr
  (code=exited, status=0/SUCCESS)
  Process: 2004 ExecStartPre=/usr/local/bin/mysql-prepare-db-dir %n
  (code=exited, status=0/SUCCESS)

Mar 31 12:39:28 cygnus mysqld_safe[2340]: 140331 12:39:28 mysqld_safe
Can't log to error log and syslog at the same time.  Remove all
--log-error configuration options for --syslog to take effect.
Mar 31 12:39:28 cygnus mysqld_safe[2340]: 140331 12:39:28 mysqld_safe
Logging to '/var/log/mysql/error.log'.
Mar 31 12:39:28 cygnus mysqld_safe[2340]: mkdir: cannot create directory
‘/var/run/mysqld’: Permission denied
Mar 31 12:39:28 cygnus mysqld_safe[2340]: chown: cannot access
‘/var/run/mysqld’: No such file or directory
Mar 31 12:39:28 cygnus mysqld_safe[2340]: chmod: cannot access
‘/var/run/mysqld’: No such file or directory
Mar 31 12:39:29 cygnus mysqld_safe[2340]: 140331 12:39:29 mysqld_safe
Starting mysqld daemon with databases from /var/lib/mysql
Mar 31 12:39:46 cygnus mysqld_safe[2340]: 140331 12:39:46 mysqld_safe
mysqld from pid file /var/run/mysqld/mysqld.pid ended
Mar 31 12:39:46 cygnus systemd[1]: mysqld.service: control process
exited, code=exited status=1
Mar 31 12:39:46 cygnus systemd[1]: Failed to start MySQL database
server.
Mar 31 12:39:46 cygnus systemd[1]: Unit mysqld.service entered failed
state.
#
---------------------------------------------------------------------------------------
# journalctl -xn
-- Logs begin at Mon 2014-01-13 09:34:08 PST, end at Mon 2014-03-31
13:44:23 PDT. --
Mar 31 13:44:21 cygnus mysqld_safe[13377]: 140331 13:44:21 mysqld_safe
Can't log to error log and syslog at the same time.  Remove all
--log-error configuration options for --syslog to take effect.
Mar 31 13:44:21 cygnus mysqld_safe[13377]: 140331 13:44:21 mysqld_safe
Logging to '/var/log/mysql/error.log'.
Mar 31 13:44:21 cygnus mysqld_safe[13377]: mkdir: cannot create
directory ‘/var/run/mysqld’: Permission denied
Mar 31 13:44:21 cygnus mysqld_safe[13377]: chown: cannot access
‘/var/run/mysqld’: No such file or directory
Mar 31 13:44:21 cygnus mysqld_safe[13377]: chmod: cannot access
‘/var/run/mysqld’: No such file or directory
Mar 31 13:44:21 cygnus mysqld_safe[13377]: 140331 13:44:21 mysqld_safe
Starting mysqld daemon with databases from /var/lib/mysql
Mar 31 13:44:22 cygnus mysqld_safe[13377]: 140331 13:44:22 mysqld_safe
mysqld from pid file /var/run/mysqld/mysqld.pid ended
Mar 31 13:44:23 cygnus systemd[1]: mysqld.service: control process
exited, code=exited status=1
Mar 31 13:44:23 cygnus systemd[1]: Failed to start MySQL database
server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation:
http://www.freedesktop.org/wiki/Software/systemd/catalog/be02cf6855d2428ba40df7e9d022f03d
-- 
-- Unit mysqld.service has failed.
-- 
-- The result is failed.
Mar 31 13:44:23 cygnus systemd[1]: Unit mysqld.service entered failed
state.
--------------------------------------------------------------------------------------- Now see; that didn't get us anywhere, did it. I've adapted these two files from Fedora as well, and no I can't find the cause of the above errors. mysqld-prepare-db-dir --------------------------------------------------------------------------------------- #!/bin/sh # This script creates the mysql data directory during first service start. # In subsequent starts, it does nothing much. # extract value of a MySQL option from config files # Usage: get_mysql_option SECTION VARNAME DEFAULT # result is returned in $result # We use my_print_defaults which prints all options from multiple files, # with the more specific ones later; hence take the last match. get_mysql_option(){ result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1` if [ -z "$result" ]; then # not found, use default result="$3" fi } # Defaults here had better match what mysqld_safe will default to get_mysql_option mysqld datadir "/var/lib/mysql" datadir="$result" get_mysql_option mysqld_safe log-error "/var/log/mysql/error.log" errlogfile="$result" get_mysql_option mysqld socket "$datadir/mysql.sock" socketfile="$result" # Absorb configuration settings from the specified systemd service file, # or the default "mysqld" service if not specified SERVICE_NAME="$1" if [ x"$SERVICE_NAME" = x ] then SERVICE_NAME=mysqld.service fi myuser=`systemctl show -p User "${SERVICE_NAME}" | sed 's/^User=//'` if [ x"$myuser" = x ] then myuser=mysql fi mygroup=`systemctl show -p Group "${SERVICE_NAME}" | sed 's/^Group=//'` if [ x"$mygroup" = x ] then mygroup=mysql fi # Set up the errlogfile with appropriate permissions touch "$errlogfile" chown "$myuser:$mygroup" "$errlogfile" chmod 0640 "$errlogfile" #[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile" # We check if there is already a process using the socket file, # since otherwise this systemd service file could report false # positive result when starting and mysqld_safe could remove # a socket file, which actually uses a different daemon. if fuser "$socketfile" > /dev/null ; then echo "Socket file $socketfile exists." >&2 echo "Is another MySQL daemon already running with the same unix socket?" >&2 exit 1 fi # 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 echo "Initializing MySQL database" /usr/bin/mysql_install_db --datadir="$datadir" --user="$myuser" ret=$? if [ $ret -ne 0 ] ; then echo "Initialization of MySQL database failed." >&2 echo "Perhaps /etc/my.cnf is misconfigured." >&2 # Clean up any partially-created database files if [ ! -e "$datadir/mysql/user.frm" ] ; then rm -rf "$datadir"/* fi exit $ret fi # In case we're running as root, make sure files are owned properly chown -R "$myuser:$mygroup" "$datadir" fi exit 0 mysqld-wait-ready --------------------------------------------------------------------------------------- #!/bin/sh # This script waits for mysqld to be ready to accept connections # (which can be many seconds or even minutes after launch, if there's # a lot of crash-recovery work to do). # Running this as ExecStartPost is useful so that services declared as # "After mysqld" won't be started until the database is really ready. # Service file passes us the daemon's PID (actually, mysqld_safe's PID) daemon_pid="$1" # extract value of a MySQL option from config files # Usage: get_mysql_option SECTION VARNAME DEFAULT # result is returned in $result # We use my_print_defaults which prints all options from multiple files, # with the more specific ones later; hence take the last match. get_mysql_option(){ result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1` if [ -z "$result" ]; then # not found, use default result="$3" fi } # Defaults here had better match what mysqld_safe will default to get_mysql_option mysqld datadir "/var/lib/mysql" datadir="$result" get_mysql_option mysqld socket "/var/lib/mysql/mysql.sock" socketfile="$result" # Wait for the server to come up or for the mysqld process to disappear ret=0 while /bin/true; do MYSQLDRUNNING=0 if [ -d "/proc/${daemon_pid}" ] ; then MYSQLDRUNNING=1 fi RESPONSE=`/usr/bin/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1` mret=$? if [ $mret -eq 0 ] && [ $MYSQLDRUNNING -eq 1 ]; then break fi # exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected, # anything else suggests a configuration error if [ $mret -ne 1 -a $mret -ne 11 ]; then ret=1 break fi # "Access denied" also means the server is alive echo "$RESPONSE" | grep -q "Access denied for user" && break # Check process still exists if ! /bin/kill -0 $daemon_pid 2>/dev/null; then ret=1 break fi sleep 1 done exit $ret
#742900#65
Date:
2014-03-31 20:59:03 UTC
From:
To:
That's the purpose of the (adapted from Fedora) mysql-wait-ready script.
 It's run --with the same pid as mysqld-safe-- so that progress is held
up until the server is ready.  I couldn't find any --nodaemonize switch
in mysqld's man page.  Maybe it is daemonizing, but then there's no way
to prevent that.  And if that were the case it would be listening on
3306, but it's not.

#742900#70
Date:
2014-03-31 21:33:11 UTC
From:
To:
Excerpts from merc1984's message of 2014-03-31 13:52:37 -0700:

Antagonizing those who are trying to help is really not going to be
productive. I for one have moved your emails and this thread to the
bottom of my priority stack here on out.

Or perhaps the problem is that you refuse to believe me that you could
solve this with a single line for loop? No.. right.. polling bad.

You likely need an ExecStartPre to mkdir this.

#742900#75
Date:
2014-03-31 21:35:32 UTC
From:
To:
Hi merc,

merc1984@f-m.fm writes:
Since you are rude and convinced that you know better what the problem
is than the actual maintainers of the software in question, I lost any
motivation to help you and will not participate in this discussion
anymore.

#742900#80
Date:
2014-03-31 23:45:11 UTC
From:
To:
Lol, can't a girl have a little fun?

Tried that, but the problem is mysql user is trying to do this, and /run
is 755.  If I go ahead and create /run/mysqld dir manually, it's erased
on the next boot.  Anyway, Fedora doesn't do anything special for some
reason;  I copied mine from them.

#742900#85
Date:
2014-03-31 23:51:53 UTC
From:
To:
Am 01.04.2014 01:45, schrieb merc1984@f-m.fm:

As far as I'm concerned I haven't found your responses to be
particularly funny, my impression sofar is that you are acting like a
smart-ass.

You might consider shipping a tmpfiles.de snippet [0] to create such a
runtime directory.

[0] http://www.freedesktop.org/software/systemd/man/tmpfiles.d.html

#742900#90
Date:
2014-03-31 23:52:49 UTC
From:
To:
Feeling a little sensitive today...

Well this is still a problem.  I can get around it, but others can't.
If I can't fix it, others can't.

I went to all the trouble of trying to fix it and logging this bug for
the good of the community.  But if you have life frustrations that make
you lash out at others and so thin-skinned, then so be it.  Idc.
Gourd-head and blow it off.  Better yet, resign mysqld if you can't
handle it.  It would be best for everyone.

#742900#95
Date:
2014-04-01 00:06:03 UTC
From:
To:
I'd thought about pitching in here, but too many of you are just
pissed-off, unhappy, angry, and inconsolable.

I am going to make this work my way, and you can figure it all out for
yourselves.

Life is too short for this kind of stupid shit.

Just a suggestion:  quit whatever job you have, and find something else.
 That would be for your own good.

#742900#100
Date:
2014-08-27 17:15:35 UTC
From:
To:
Now, Systemd Is in service so much in the version  Sid and testing, Debian has
not the file mysqld.service so mysql can't start or stop with Systemd, It is
really boring, could please repair you relatively quickly this problem,
because it impacte many using applications mysql.

#742900#105
Date:
2014-11-23 13:57:22 UTC
From:
To:
I've got mysql running with a systemd service file on my machine. As was
suggested earlier in the bug report, I started with the fedora scripts so
there may be some fedoraisms to check on. The only problem I had just using
them was an issue with mysql-wait-ready where the ping line was improperly
formated resulting in usage info getting printed out. As you can see, I
added a little bit of extra output around that section to help debug.
Since /usr/bin/mysqld_safe sources /etc/mysql/debian.cnf and systemd runs
everything as the mysql user, I also had to chgrp mysql
/etc/mysql/debian.cnf; chmod g+r /etc/mysql/debian.cnf.



####################### mysql.service
# For more info about custom unit files, see systemd.unit(5) or
#
http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# For example, if you want to increase mysql's open-files-limit to 10000,
# you need to increase systemd's LimitNOFILE setting, so create a file named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
#       [Service]
#       LimitNOFILE=10000

[Unit]
Description=MySQL database server
After=syslog.target network.target

[Service]
Type=simple
User=mysql
Group=mysql

ExecStartPre=/usr/bin/mysql-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux
alarms,
# per bug #547485
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/bin/mysql-wait-ready $MAINPID

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

# Security
PrivateTmp=yes
#InaccessibleDirectories=/boot /.config /home/backups /home/bill
/home/sleeper /lib32 /media /mnt /opt /proc /root /srv /sys
#ReadOnlyDirectories=/bin /etc /sbin /usr
#CapabilityBoundingSet=~CAP_SYS_PTRACE
#DeviceAllow=/dev/null rw
#NoNewPrivileges=yes

[Install]
WantedBy=multi-user.target



####################### /usr/bin/mysql-prepare-db-dir
#!/bin/sh

# This script creates the mysql data directory during first service start.
# In subsequent starts, it does nothing much.

# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
        result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" |
        tail -n 1`
        if [ -z "$result" ]; then
            # not found, use default
            result="$3"
        fi
}

# Defaults here had better match what mysqld_safe will default to
get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld_safe log-error "/var/log/mysql/error.log"
errlogfile="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"

# Absorb configuration settings from the specified systemd service file,
# or the default "mysqld" service if not specified
SERVICE_NAME="$1"
if [ x"$SERVICE_NAME" = x ]
then
    SERVICE_NAME=mysqld.service
fi

myuser=`systemctl show -p User "${SERVICE_NAME}" |
  sed 's/^User=//'`
if [ x"$myuser" = x ]
then
    myuser=mysql
fi

mygroup=`systemctl show -p Group "${SERVICE_NAME}" |
  sed 's/^Group=//'`
if [ x"$mygroup" = x ]
then
    mygroup=mysql
fi

# Set up the errlogfile with appropriate permissions
touch "$errlogfile"
chown "$myuser:$mygroup" "$errlogfile"
chmod 0640 "$errlogfile"
#[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"

# We check if there is already a process using the socket file,
# since otherwise this systemd service file could report false
# positive result when starting and mysqld_safe could remove
# a socket file, which actually uses a different daemon.
if fuser "$socketfile" > /dev/null ; then
    echo "Socket file $socketfile exists." >&2
    echo "Is another MySQL daemon already running with the same unix
    socket?" >&2
    exit 1
fi

# 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
    echo "Initializing MySQL database"
    /usr/bin/mysql_install_db --datadir="$datadir" --user="$myuser"
    ret=$?
    if [ $ret -ne 0 ] ; then
        echo "Initialization of MySQL database failed." >&2
        echo "Perhaps /etc/my.cnf is misconfigured." >&2
        # Clean up any partially-created database files
        if [ ! -e "$datadir/mysql/user.frm" ] ; then
            rm -rf "$datadir"/*
        fi
        exit $ret
    fi
    # In case we're running as root, make sure files are owned properly
    chown -R "$myuser:$mygroup" "$datadir"
fi

exit 0



####################### /usr/bin/mysql-wait-ready
#!/bin/sh

# This script waits for mysqld to be ready to accept connections
# (which can be many seconds or even minutes after launch, if there's
# a lot of crash-recovery work to do).
# Running this as ExecStartPost is useful so that services declared as
# "After mysqld" won't be started until the database is really ready.

# Service file passes us the daemon's PID (actually, mysqld_safe's PID)
daemon_pid="$1"

# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" |
tail -n 1`
if [ -z "$result" ]; then
    # not found, use default
    result="$3"
fi
}

# Defaults here had better match what mysqld_safe will default to
get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld socket "/var/lib/mysql/mysql.sock"
socketfile="$result"

# Wait for the server to come up or for the mysqld process to disappear
ret=0
while /bin/true; do
MYSQLDRUNNING=0
if [ -d "/proc/${daemon_pid}" ] ; then
    MYSQLDRUNNING=1
fi
RESPONSE=`/usr/bin/mysqladmin --no-defaults --socket="$socketfile"
--user=UNKNOWN_MYSQL_USER ping 2>&1`
mret=$?
if [ $mret -eq 0 ] && [ $MYSQLDRUNNING -eq 1 ]; then
    break
fi
# exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,
# anything else suggests a configuration error
if [ $mret -ne 1 -a $mret -ne 11 ]; then
            echo "Received bad response from mysql..."
            echo "$RESPONSE"
            echo "$mret"
    ret=1
    break
fi
# "Access denied" also means the server is alive
echo "$RESPONSE" | grep -q "Access denied for user" && break

# Check process still exists
if ! /bin/kill -0 $daemon_pid 2>/dev/null; then
            echo "Process does not exist"
    ret=1
    break
fi
sleep 1
done

exit $ret

#742900#110
Date:
2014-11-24 19:52:02 UTC
From:
To:
affects + mariadb-10.0

Also MariaDB needs a systemd file, which I assume would be identical
with the one for MySQL. Actually there are multiple attempts at this,
one in every distro. See issue
https://mariadb.atlassian.net/browse/MDEV-427 and comment number 2 by
me, which lists the systemd files in different distros.

We would need a systemd guru here to tell us which of the scripts is
best and then we could settle on it for both mysql and mariadb at
least in Debian, and send it upstream for official inclusion and
long-term support.

#742900#115
Date:
2021-09-07 05:41:27 UTC
From:
To:
Ek het hierdie sakegeleentheid -voorstel vir u wat ons sal baat; Ek sal ook
daarvan hou dat jy dit sien.

Groete,
Frank William
64 980 4011