LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can I add a delay for mysql in chkconfig? (https://www.linuxquestions.org/questions/linux-newbie-8/can-i-add-a-delay-for-mysql-in-chkconfig-4175429405/)

mmorton89 09-28-2012 04:05 AM

Can I add a delay for mysql in chkconfig?
 
So I am running a java game server that uses mysql databases for storing information. I have both the java game server and mysql setup in chkconfig to start on server reboot.

The problem is when I do reboot the machine, the game server cannot connect to the mysql databases. All I have to do is stop the game server and restart it shortly after the reboot and it works perfectly fine.

So I assume, because of this, that for some reason mysql is not ready when the game server tries to connect to the databases, since they both start at the same time.

So is there a way to fix this? I have considered changing my crontab to doing a reboot say at midnight, then starting the game server at say 12:05 and removing the gameserver from start on reboot.

If there is a more simple solution, like having a delay on certain services in the chkconfig I would much rather do that. I could not find anything though, hopefully you guys can help. :D

Thanks

Edit - Sorry about the title, I meant to put a add a delay on a service in chkconfig not mysql :-/

acid_kewpie 09-28-2012 04:47 AM

You want to want *delay* the stuff that isn't ready yet?? How does that make sense? You can edit the chkconfig stanza at teh top of a service script and modify the start / stop numbers and then (i presume) turn the service off and on again with chkconfig as normal, but surely' it's the game server you need to delay..?

mmorton89 09-28-2012 05:12 AM

Quote:

Originally Posted by acid_kewpie (Post 4791410)
You want to want *delay* the stuff that isn't ready yet?? How does that make sense? You can edit the chkconfig stanza at teh top of a service script and modify the start / stop numbers and then (i presume) turn the service off and on again with chkconfig as normal, but surely' it's the game server you need to delay..?

Yes, I edited the post, I accidently put mysql when I did mean to put the game server. I as using a script for the game server but I only see run levels.

Code:

### BEGIN INIT INFO
# Provides: minecraft
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Minecraft server
# Description: Starts the CraftBukkit Minecraft server
### END INIT INFO


acid_kewpie 09-28-2012 05:30 AM

ah, LSB scripts, barely touched them... OK, so you can make mysql a dependency there... set "Required-Start: mysql $local_fs $remote_fs" and try that

mmorton89 09-28-2012 05:52 AM

Quote:

Originally Posted by acid_kewpie (Post 4791435)
ah, LSB scripts, barely touched them... OK, so you can make mysql a dependency there... set "Required-Start: mysql $local_fs $remote_fs" and try that

That does not seem to work, I tried both mysql and mysqld.

mmorton89 09-28-2012 07:40 AM

What about Should-Start:

beroteme 09-28-2012 08:32 AM

Hi mmorton89

There are now 2 different init systems for starting programs at startup. The old system is the sysv init.d

* There are scripts (usually in /etc/init.d) which control the processes with start, stop, restart, etc
* There are also directories like /etc/rc<n>.d where the <n> is the runlevel. In there there are usually sym links to the scripts in /etc/init.d.
* The scripts either have a S<n> or K<n> prefix. S for start K for stop. The number is the order they are processed in

If your using a linux kernel pre v3 you'll more then likely have the above. You can use a lower number for mysql than your game server to get the ordering... however mysql can take along time to start if you have large bufferpools set or have innodb errors. Really the games server should check to see if it can connect to mysql and wait if it's not running or starting.

OK so if you have a more recent kernel version you'll be using the new init system (systemd) which is event based and has scripts int /etc/init/... in these files you can set dependencies on other services.

pampers 09-28-2012 12:14 PM

As far as I know (correct me someone if I'm wrong) when the system is starting services, it doesn't continue to the next service until it doesn't complete to start a specific service, so is weird for me that if the system wants to start mysql server it continues with other services without checking if mysql completes to start or not??? At least, for me the OS doesn't work this way....maybe I'm wrong, but as far as I know it doesn't work this way. But, if mysql and the java game are one next to each other on boot , probably the suggestion of beroteme could work for you, put mysql service first and java game to one of the last services to start.

mmorton89 09-28-2012 07:05 PM

Quote:

Originally Posted by beroteme (Post 4791553)
Hi mmorton89

There are now 2 different init systems for starting programs at startup. The old system is the sysv init.d

* There are scripts (usually in /etc/init.d) which control the processes with start, stop, restart, etc
* There are also directories like /etc/rc<n>.d where the <n> is the runlevel. In there there are usually sym links to the scripts in /etc/init.d.
* The scripts either have a S<n> or K<n> prefix. S for start K for stop. The number is the order they are processed in

If your using a linux kernel pre v3 you'll more then likely have the above. You can use a lower number for mysql than your game server to get the ordering... however mysql can take along time to start if you have large bufferpools set or have innodb errors. Really the games server should check to see if it can connect to mysql and wait if it's not running or starting.

OK so if you have a more recent kernel version you'll be using the new init system (systemd) which is event based and has scripts int /etc/init/... in these files you can set dependencies on other services.

Ok, my server has both /etc/init and /etc/init.d and my scripts are all in /etc/init.d

mysqld is listed as S64
minecraft script is listed as S50

Is this why mysqld is not started before the minecraft script is?
Also if I change the numbers, will this fix my issue?

Edit - I just changed the minecraft script from S50minecraft to S91minecraft on all the run levels and it still did not work. :-/

beroteme 10-02-2012 06:08 AM

@pampers:

On newer systems (systemd) the scripts can run concurrently .
In both the old and new init systems if a start job fails (say ssh for example) the other scripts will still be attempted it just that that sshd program would not be running once the system is fully up. The problem with some scripts is that the script can finish but the program is still initializing and so you can have a race condition with other startup scripts which rely on that particular program to be running.

mmorton89:

Ok so your running the newer init system as you have '/etc/init'. The old system still exists for compatibility and if you try to restart a service as root by '/etc/init.d/<progname> restart' you'll get a warning that the it's redirecting the request to the systemd system.

You mentioned you changed the scripts in '/etc/init.d/' prefixed with S64 and S50 but these scripts should not live in that directory. They should live in something like '/etc/rc<n>.d' where <n> is your runlevel. If you type 'runlevel' it will give you your current runlevel.

Can you send me the output from the runlevel command. Also send me the directory listing of the /etc/rc<n>.d/ directory. and also the directory listing of your /etc/init/ directory. The reason for this is that there is a small thing I left out. In the new system some programs may not support the new systemd scripts and so uses the older system (hence having both). It could be possible that mysql uses the new system and your games server uses the old which makes the solution a little harder to achieve.

mmorton89 10-02-2012 02:42 PM

Quote:

Originally Posted by beroteme (Post 4794786)
@pampers:

On newer systems (systemd) the scripts can run concurrently .
In both the old and new init systems if a start job fails (say ssh for example) the other scripts will still be attempted it just that that sshd program would not be running once the system is fully up. The problem with some scripts is that the script can finish but the program is still initializing and so you can have a race condition with other startup scripts which rely on that particular program to be running.

mmorton89:

Ok so your running the newer init system as you have '/etc/init'. The old system still exists for compatibility and if you try to restart a service as root by '/etc/init.d/<progname> restart' you'll get a warning that the it's redirecting the request to the systemd system.

You mentioned you changed the scripts in '/etc/init.d/' prefixed with S64 and S50 but these scripts should not live in that directory. They should live in something like '/etc/rc<n>.d' where <n> is your runlevel. If you type 'runlevel' it will give you your current runlevel.

Can you send me the output from the runlevel command. Also send me the directory listing of the /etc/rc<n>.d/ directory. and also the directory listing of your /etc/init/ directory. The reason for this is that there is a small thing I left out. In the new system some programs may not support the new systemd scripts and so uses the older system (hence having both). It could be possible that mysql uses the new system and your games server uses the old which makes the solution a little harder to achieve.

I didn't change the scripts in '/etc/init.d' I changed them in '/etc/rc<2-5>.d'

Here is the output of chkconfig
Code:

[root@server ~]# chkconfig
NetworkManager  0:off  1:off  2:on    3:on    4:on    5:on    6:off
abrtd          0:off  1:off  2:off  3:on    4:off  5:on    6:off
acpid          0:off  1:off  2:on    3:on    4:on    5:on    6:off
atd            0:off  1:off  2:off  3:on    4:on    5:on    6:off
auditd          0:off  1:off  2:on    3:on    4:on    5:on    6:off
avahi-daemon    0:off  1:off  2:off  3:on    4:on    5:on    6:off
cgconfig        0:off  1:off  2:off  3:off  4:off  5:off  6:off
cgred          0:off  1:off  2:off  3:off  4:off  5:off  6:off
cpuspeed        0:off  1:on    2:on    3:on    4:on    5:on    6:off
crond          0:off  1:off  2:on    3:on    4:on    5:on    6:off
da-popb4smtp    0:off  1:off  2:on    3:on    4:on    5:on    6:off
directadmin    0:off  1:off  2:on    3:on    4:on    5:on    6:off
dnsmasq        0:off  1:off  2:off  3:off  4:off  5:off  6:off
dovecot        0:off  1:off  2:on    3:on    4:on    5:on    6:off
exim            0:off  1:off  2:on    3:on    4:on    5:on    6:off
haldaemon      0:off  1:off  2:off  3:on    4:on    5:on    6:off
httpd          0:off  1:off  2:on    3:on    4:on    5:on    6:off
ip6tables      0:off  1:off  2:on    3:on    4:on    5:on    6:off
iptables        0:off  1:off  2:on    3:on    4:on    5:on    6:off
irqbalance      0:off  1:off  2:off  3:on    4:on    5:on    6:off
jexec          0:on    1:on    2:on    3:on    4:on    5:on    6:on
kdump          0:off  1:off  2:off  3:on    4:on    5:on    6:off
lvm2-monitor    0:off  1:on    2:on    3:on    4:on    5:on    6:off
mdmonitor      0:off  1:off  2:on    3:on    4:on    5:on    6:off
messagebus      0:off  1:off  2:on    3:on    4:on    5:on    6:off
minecraft      0:off  1:off  2:on    3:on    4:on    5:on    6:off
mysqld          0:off  1:off  2:on    3:on    4:on    5:on    6:off
named          0:off  1:off  2:off  3:off  4:off  5:off  6:off
netconsole      0:off  1:off  2:off  3:off  4:off  5:off  6:off
netfs          0:off  1:off  2:off  3:on    4:on    5:on    6:off
network        0:off  1:off  2:on    3:on    4:on    5:on    6:off
portreserve    0:off  1:off  2:on    3:on    4:on    5:on    6:off
proftpd        0:off  1:off  2:off  3:on    4:on    5:on    6:off
psacct          0:off  1:off  2:off  3:off  4:off  5:off  6:off
quota_nld      0:off  1:off  2:off  3:off  4:off  5:off  6:off
rdisc          0:off  1:off  2:off  3:off  4:off  5:off  6:off
restorecond    0:off  1:off  2:off  3:off  4:off  5:off  6:off
rsyslog        0:off  1:off  2:on    3:on    4:on    5:on    6:off
saslauthd      0:off  1:off  2:off  3:off  4:off  5:off  6:off
smartd          0:off  1:off  2:off  3:off  4:off  5:off  6:off
sshd            0:off  1:off  2:on    3:on    4:on    5:on    6:off
startips        0:off  1:off  2:on    3:on    4:on    5:on    6:off
sysstat        0:off  1:on    2:on    3:on    4:on    5:on    6:off
udev-post      0:off  1:on    2:on    3:on    4:on    5:on    6:off
vncserver      0:off  1:off  2:off  3:off  4:off  5:off  6:off
wpa_supplicant  0:off  1:off  2:off  3:off  4:off  5:off  6:off

Here is '/etc/init' and '/etc/init.d'
Code:

[root@server ~]# cd /etc/init
[root@server init]# ls
control-alt-delete.conf  rc.conf                          serial.conf
init-system-dbus.conf    rcS.conf                        splash-manager.conf
kexec-disable.conf      rcS-sulogin.conf                start-ttys.conf
plymouth-shutdown.conf  readahead-collector.conf        tty.conf
prefdm.conf              readahead.conf
quit-plymouth.conf      readahead-disable-services.conf
[root@server rc5.d]# cd /etc/init.d
[root@server init.d]# ls
abrtd        dnsmasq    kdump          netfs          saslauthd
acpid        dovecot    killall        network        single
atd          exim        lvm2-monitor  NetworkManager  smartd
auditd        functions  mdmonitor      portreserve    sshd
avahi-daemon  haldaemon  messagebus    proftpd        startips
cgconfig      halt        microcode_ctl  psacct          sysstat
cgred        httpd      minecraft      quota_nld      udev-post
cpuspeed      ip6tables  mysqld        rdisc          vncserver
crond        iptables    named          restorecond    wpa_supplicant
da-popb4smtp  irqbalance  named.back    rsyslog
directadmin  jexec      netconsole    sandbox

minecraft and mysql are both on runlevels 2-5
Code:

[root@server init.d]# cd /etc/rc2.d
[root@server rc2.d]# ls
K01smartd        K75netfs          S08iptables        S50msm
K02avahi-daemon  K75quota_nld      S10network        S54dovecot
K05atd          K80kdump          S11auditd          S55sshd
K10psacct        K84wpa_supplicant  S11portreserve    S64mysqld
K10saslauthd    K86cgred          S11startips        S80da-popb4smtp
K15proftpd      K87irqbalance      S12rsyslog        S80directadmin
K16abrtd        K87restorecond    S13cpuspeed        S80exim
K35vncserver    K89rdisc          S15mdmonitor      S85httpd
K45named        K95cgconfig        S22messagebus      S90crond
K50dnsmasq      S01sysstat        S23NetworkManager  S91minecraft
K50netconsole    S02lvm2-monitor    S26acpid          S95jexec
K74haldaemon    S08ip6tables      S26udev-post      S99local
[root@server rc1.d]# cd /etc/rc3.d
[root@server rc3.d]# ls
K01smartd          K95cgconfig      S15mdmonitor      S64mysqld
K10psacct          S01sysstat      S20kdump          S80da-popb4smtp
K10saslauthd      S02lvm2-monitor  S22messagebus      S80directadmin
K35vncserver      S08ip6tables    S23NetworkManager  S80exim
K45named          S08iptables      S24avahi-daemon    S82abrtd
K50dnsmasq        S10network      S25netfs          S85httpd
K50netconsole      S11auditd        S26acpid          S85proftpd
K75quota_nld      S11portreserve  S26haldaemon      S90crond
K84wpa_supplicant  S11startips      S26udev-post      S91minecraft
K86cgred          S12rsyslog      S50msm            S95atd
K87restorecond    S13cpuspeed      S54dovecot        S95jexec
K89rdisc          S13irqbalance    S55sshd            S99local
[root@server rc3.d]# cd /etc/rc4.d
[root@server rc4.d]# ls
K01smartd          K89rdisc        S13irqbalance      S55sshd
K10psacct          K95cgconfig      S15mdmonitor      S64mysqld
K10saslauthd      S01sysstat      S20kdump          S80da-popb4smtp
K16abrtd          S02lvm2-monitor  S22messagebus      S80directadmin
K35vncserver      S08ip6tables    S23NetworkManager  S80exim
K45named          S08iptables      S24avahi-daemon    S85httpd
K50dnsmasq        S10network      S25netfs          S85proftpd
K50netconsole      S11auditd        S26acpid          S90crond
K75quota_nld      S11portreserve  S26haldaemon      S91minecraft
K84wpa_supplicant  S11startips      S26udev-post      S95atd
K86cgred          S12rsyslog      S50msm            S95jexec
K87restorecond    S13cpuspeed      S54dovecot        S99local
[root@server rc4.d]# cd /etc/rc5.d
[root@server rc5.d]# ls
K01smartd          K95cgconfig      S15mdmonitor      S64mysqld
K10psacct          S01sysstat      S20kdump          S80da-popb4smtp
K10saslauthd      S02lvm2-monitor  S22messagebus      S80directadmin
K35vncserver      S08ip6tables    S23NetworkManager  S80exim
K45named          S08iptables      S24avahi-daemon    S82abrtd
K50dnsmasq        S10network      S25netfs          S85httpd
K50netconsole      S11auditd        S26acpid          S85proftpd
K75quota_nld      S11portreserve  S26haldaemon      S90crond
K84wpa_supplicant  S11startips      S26udev-post      S91minecraft
K86cgred          S12rsyslog      S50msm            S95atd
K87restorecond    S13cpuspeed      S54dovecot        S95jexec
K89rdisc          S13irqbalance    S55sshd            S99local

I think I got everything you asked for.

jsaravana87 10-03-2012 12:21 AM

Hi,

You should change the startup order of these services in /etc/rc<2-5>d

Code:
ls -al /etc/rc3.d/*mysql*
lrwxrwxrwx. 1 root root 16 Oct 03 20:14 /etc/rc3.d/S64mysqld -> ../init.d/mysqld

Default chconfig level value for mysql

# chkconfig: - 64 36

change the chkconfig value to new priority value

change minecraft to 64 and mysqld to 50
Quote:


mysqld is listed as S64
minecraft script is listed as S50
mysql change as below in startup script

Code:
# chkconfig: - 50 36 .50 is the new starting priority. You have to set a priority a just less than your minecraft prioriy
Even then you are facing problem run the below command to make mysql to pick new priority value

Quote:

chkconfig mysqld resetpriorities

mmorton89 10-08-2012 12:52 PM

Quote:

Originally Posted by arun5002 (Post 4795653)
Hi,

You should change the startup order of these services in /etc/rc<2-5>d

Code:
ls -al /etc/rc3.d/*mysql*
lrwxrwxrwx. 1 root root 16 Oct 03 20:14 /etc/rc3.d/S64mysqld -> ../init.d/mysqld

Default chconfig level value for mysql

# chkconfig: - 64 36

change the chkconfig value to new priority value

change minecraft to 64 and mysqld to 50

mysql change as below in startup script

Code:
# chkconfig: - 50 36 .50 is the new starting priority. You have to set a priority a just less than your minecraft prioriy
Even then you are facing problem run the below command to make mysql to pick new priority value

Sorry for the late response, but how exactly do you change the starting priorities?

I tried to manually rename the files as in..
Code:

mv S64mysqld S50mysqld
But it did not seem to work.

jsaravana87 10-09-2012 12:11 AM

Hi

To enable mysqld with low priority you have execute the below cammandline


#chkconfig mysqld resetpriorities

slavash 10-09-2012 02:39 AM

You can do a Service Dependencies:
http://mathias-kettner.de/checkmk_se...endencies.html


All times are GMT -5. The time now is 06:09 AM.