OpenWrt Forum Archive

Topic: Mysql auto start after power failure or reboot.

The content of this topic has been archived on 29 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello all!
I'm facing an issue with the mysql on the mr3020 (BARRIER BREAKER 14.07, r42625), it does not autostart after a power failure or a reboot.

I already have the script mysqld enabled on the inid.d:

/etc/init.d/mysqld enbale

Although it only starts when I do it manually:

/etc/init.d/mysqld start

Everything works as expected until I power cycle the router.

What can be causing this?
Is this an issue or just a config step I may missed?
If it's an issue, there is any workaround?

This is the mysqld script (/etc/init.d/mysqld)

#!/bin/sh /etc/rc.common
# Copyright (C) 2010-2011 OpenWrt.org

START=95
STOP=10

SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
SERVICE_STOP_TIME=9

error() {
        echo "${initscript}:" "$@" 1>&2
}

start() {
        local datadir=$(sed -n -e "s/^[[:space:]]*datadir[[:space:]]*=[[:space:]
        if [ ! -d "$datadir" ]; then
                error "Error: datadir '$datadir' in /etc/my.cnf doesn't exist"
                return 1
        fi
        if [ ! -f "$datadir/mysql/tables_priv.MYD" ]; then
                error "Error: I didn't detect a privileges table, you might need
                return 1
        fi
        service_start /usr/bin/mysqld
}

stop() {
        service_stop /usr/bin/mysqld
}

(Last edited by evilmonkey on 17 Aug 2016, 17:03)

evilmonkey wrote:

Hello all!
I'm facing an issue with the mysql on the mr3020 (BARRIER BREAKER 14.07, r42625), it does not autostart after a power failure or a reboot.

I already have the script mysqld enabled on the inid.d:

/etc/init.d/mysqld enbale

Although it only starts when I do it manually:

/etc/init.d/mysqld start

Everything works as expected until I power cycle the router.

What can be causing this?
Is this an issue or just a config step I may missed?
If it's an issue, there is any workaround?

This is the mysqld script (/etc/init.d/mysqld)

#!/bin/sh /etc/rc.common
# Copyright (C) 2010-2011 OpenWrt.org

START=95
STOP=10

SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
SERVICE_STOP_TIME=9

error() {
        echo "${initscript}:" "$@" 1>&2
}

start() {
        local datadir=$(sed -n -e "s/^[[:space:]]*datadir[[:space:]]*=[[:space:]
        if [ ! -d "$datadir" ]; then
                error "Error: datadir '$datadir' in /etc/my.cnf doesn't exist"
                return 1
        fi
        if [ ! -f "$datadir/mysql/tables_priv.MYD" ]; then
                error "Error: I didn't detect a privileges table, you might need
                return 1
        fi
        service_start /usr/bin/mysqld
}

stop() {
        service_stop /usr/bin/mysqld
}

Is there an information in logread, whats wrong? Try change in init script the start number.
Disable mysqld, change number to 99 (last service which will start) and enable it again.

(Last edited by milankocvara on 18 Aug 2016, 07:01)

milankocvara wrote:

Is there an information in logread, whats wrong? Try change in init script the start number.
Disable mysqld, change number to 99 (last service which will start) and enable it again.

Thanks for the hint. This is what I've done so far:

I took a look over the log and didn't saw anything related with the mysql that shows error messages.

I already gave a try to your suggestion, changing the starting point of the mysql, but it stills the same.

evilmonkey wrote:

I already have the script mysqld enabled on the inid.d:

/etc/init.d/mysqld enbale

Although it only starts when I do it manually

That might might just a typo in your post, but that should be "enable" instead of "enbale".

If you have enabled it successfully, there should be the symlink in /etc/rc.d/ directory for the "start at boot" functionality. Likely S99mysqld (if the new start value is 99). Verify that the symlink is there.

root@lede:~# ls -l /etc/rc.d/
...
lrwxrwxrwx    1 root     root            16 Aug 18 11:14 K99umount -> ../init.d/umount
lrwxrwxrwx    1 root     root            20 Aug 18 11:14 S00sysfixtime -> ../init.d/sysfixtime
lrwxrwxrwx    1 root     root            14 Aug 18 11:14 S10boot -> ../init.d/boot
lrwxrwxrwx    1 root     root            16 Aug 18 11:14 S10system -> ../init.d/system
lrwxrwxrwx    1 root     root            16 Aug 18 11:14 S11sysctl -> ../init.d/sysctl
lrwxrwxrwx    1 root     root            13 Aug 18 11:14 S12log -> ../init.d/log
lrwxrwxrwx    1 root     root            14 Aug 18 11:14 S12rpcd -> ../init.d/rpcd
lrwxrwxrwx    1 root     root            17 Aug 18 11:14 S19dnsmasq -> ../init.d/dnsmasq
...
evilmonkey wrote:
milankocvara wrote:

Is there an information in logread, whats wrong? Try change in init script the start number.
Disable mysqld, change number to 99 (last service which will start) and enable it again.

Thanks for the hint. This is what I've done so far:

I took a look over the log and didn't saw anything related with the mysql that shows error messages.

I already gave a try to your suggestion, changing the starting point of the mysql, but it stills the same.

If the startup script is linked in your rc.d, it is possible, that your router obtaining IP adress from your ISP over DHCP? Which IP is in your /etc/my.cnf in row bind address?

hnyman wrote:

...
If you have enabled it successfully, there should be the symlink in /etc/rc.d/ directory for the "start at boot" functionality. Likely S99mysqld (if the new start value is 99). Verify that the symlink is there.
...

Thanks for the hint, the symlink is there (/etc/rc.d/ S99mysqld).
And about enable miswrite, I just typed it wrong on the post.

milankocvara wrote:

If the startup script is linked in your rc.d, it is possible, that your router obtaining IP adress from your ISP over DHCP? Which IP is in your /etc/my.cnf in row bind address?

The router itself, the openwrt one, where the mysql is installed, is connected (fixed ip address) to other router. Both have dhcp enabled, so they are in different subnets, but both have access to internet.

On the row you asked for, I got the standard ip address for the localhost:

bind-address            = 127.0.0.1

Thanks for your reply!

evilmonkey wrote:
hnyman wrote:

...
If you have enabled it successfully, there should be the symlink in /etc/rc.d/ directory for the "start at boot" functionality. Likely S99mysqld (if the new start value is 99). Verify that the symlink is there.
...

Thanks for the hint, the symlink is there (/etc/rc.d/ S99mysqld).
And about enable miswrite, I just typed it wrong on the post.

milankocvara wrote:

If the startup script is linked in your rc.d, it is possible, that your router obtaining IP adress from your ISP over DHCP? Which IP is in your /etc/my.cnf in row bind address?

The router itself, the openwrt one, where the mysql is installed, is connected (fixed ip address) to other router. Both have dhcp enabled, so they are in different subnets, but both have access to internet.

On the row you asked for, I got the standard ip address for the localhost:

bind-address            = 127.0.0.1

Thanks for your reply!

Until you find clean solution, try this dirty workaround

type this into your rc.local

sleep 300
/etc/init.d/mysqld start

time to sleep change to the shrotest time, after which will mysql start.
it should  solve (dirty solve) this error.

(Last edited by milankocvara on 22 Aug 2016, 04:48)

milankocvara wrote:

...
Until you find clean solution, try this dirty workaround

type this into your rc.local

sleep 300
/etc/init.d/mysqld start

time to sleep change to the shrotest time, after which will mysql start.
it should  solve (dirty solve) this error.

Thanks again!
I just tried this and now the mysqld autostarts, it takes a little bit to start but it works fine.
Now that you said, I tried this solution before in my other router, it worked.
For me this solution is good enough as it solves my problem, but I'll investigate more to see if I can find a better solution for this issue and discover why the autostart isn't working properly.
Do you saw this problem earlier or have any ideas about why this issue occours?

For anyone with the mysql autostarting problem, the solution mentioned by milankocvara works good, although the problem isn't properly solved, once the reason for the mysql to not autostart wasn't fixed.
The workaround works fine, it was tested on BARRIER BREAKER (14.07, r42625) on the TP-LINK MR3020. It should work fine in other routers and versions of the openwrt if the mysqld is properly installed and working good when started manually.

Thanks!

evilmonkey wrote:
milankocvara wrote:

Until you find clean solution, try this dirty workaround

type this into your rc.local

sleep 300
/etc/init.d/mysqld start

I just tried this and now the mysqld autostarts, it takes a little bit to start but it works fine.
...
Do you saw this problem earlier or have any ideas about why this issue occours?

The boot process is partially asynchronous, so that various services initiate the startup process in the defined order, but it is not guaranteed that the startup of a service at an earlier priority is completed before the next one starts. Based on the evidence it looks like some service that is required by mysqld, starts so slowly that it is not yet ready when mysqld tries to start at boot.

The additional 300 second delay ensures that all other services have started, before mysqld starts.

Waiting 300 seconds is probably overkill. You might test with 10-30-60 seconds delays.
You can also insert "sleep 30" directly to the mysqld startup script (instead of using rc.local)

hnyman wrote:

The boot process is partially asynchronous, so that various services initiate the startup process in the defined order, but it is not guaranteed that the startup of a service at an earlier priority is completed before the next one starts. Based on the evidence it looks like some service that is required by mysqld, starts so slowly that it is not yet ready when mysqld tries to start at boot.

The additional 300 second delay ensures that all other services have started, before mysqld starts.

Waiting 300 seconds is probably overkill. You might test with 10-30-60 seconds delays.
You can also insert "sleep 30" directly to the mysqld startup script (instead of using rc.local)

I thought this too! I also think that the reason it fails to autostart is because one or more services are not up yet at the moment mysql tries to start.

I tried a sleep with a 10 seconds time and it worked good (/etc/rc.local).

...
sleep 10
/etc/init.d/mysqld
...

Wacthing by this side, I think that although this isn't a clean solution, 10 seconds isn't much time and everything is up quickly. Also I think that It's worthed go further on this to know what services mysqld need, for the knowledge (I don't know what services are related to the mysql), it could be silly to someone experienced on it. It may be possible to solve this changing the way some services go up but it could mess with other stuff related to software/hardware causing other issues, so i think that waiting 10 seconds after almost everything is up isn't bad at all.

Thanks!

(Last edited by evilmonkey on 22 Aug 2016, 16:00)

evilmonkey wrote:
hnyman wrote:

The boot process is partially asynchronous, so that various services initiate the startup process in the defined order, but it is not guaranteed that the startup of a service at an earlier priority is completed before the next one starts. Based on the evidence it looks like some service that is required by mysqld, starts so slowly that it is not yet ready when mysqld tries to start at boot.

The additional 300 second delay ensures that all other services have started, before mysqld starts.

Waiting 300 seconds is probably overkill. You might test with 10-30-60 seconds delays.
You can also insert "sleep 30" directly to the mysqld startup script (instead of using rc.local)

I thought this too! I also think that the reason it fails to autostart is because one or more services are not up yet at the moment mysql tries to start.

I tried a sleep with a 10 seconds time and it worked good (/etc/rc.local).

...
sleep 10
/etc/init.d/mysqld
...

Wacthing by this side, I think that although this isn't a clean solution, 10 seconds isn't much time and everything is up quickly. Also I think that It's worthed go further on this to know what services mysqld need, for the knowledge (I don't know what services are related to the mysql), it could be silly to someone experienced on it. It may be possible to solve this changing the way some services go up but it could mess with other stuff related to software/hardware causing other issues, so i think that waiting 10 seconds after almost everything is up isn't bad at all.

Thanks!

I dont know, if in default OpenWRT utility "logger" is (im using just part of this system and I have it In) but you can try in the end of each startup script (in the end of starting section) write lines

Into /etc/init.d/network

logger EndOfLoadNetwork

into /etc/init.d/mysqld

logger EndOfLoadMysqld

.
.
.
and then after reboot your router will/could be in logread  these lines in the row as the processes started.
I think, there will be some isue about network and mysql...

(Last edited by milankocvara on 22 Aug 2016, 18:04)

The discussion might have continued from here.