LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-28-2012, 04:05 AM   #1
mmorton89
LQ Newbie
 
Registered: Jul 2012
Location: Columbus, OH
Distribution: Centos 6.3
Posts: 20

Rep: Reputation: Disabled
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.

Thanks

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

Last edited by mmorton89; 09-28-2012 at 04:08 AM.
 
Old 09-28-2012, 04:47 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
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..?
 
Old 09-28-2012, 05:12 AM   #3
mmorton89
LQ Newbie
 
Registered: Jul 2012
Location: Columbus, OH
Distribution: Centos 6.3
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by acid_kewpie View Post
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
 
Old 09-28-2012, 05:30 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
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
 
Old 09-28-2012, 05:52 AM   #5
mmorton89
LQ Newbie
 
Registered: Jul 2012
Location: Columbus, OH
Distribution: Centos 6.3
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by acid_kewpie View Post
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.
 
Old 09-28-2012, 07:40 AM   #6
mmorton89
LQ Newbie
 
Registered: Jul 2012
Location: Columbus, OH
Distribution: Centos 6.3
Posts: 20

Original Poster
Rep: Reputation: Disabled
What about Should-Start:
 
Old 09-28-2012, 08:32 AM   #7
beroteme
LQ Newbie
 
Registered: Sep 2012
Distribution: nix
Posts: 2

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 09-28-2012, 12:14 PM   #8
pampers
LQ Newbie
 
Registered: Sep 2012
Location: Chile
Distribution: Slackware Current - RedHat Enterprise
Posts: 16

Rep: Reputation: Disabled
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.
 
Old 09-28-2012, 07:05 PM   #9
mmorton89
LQ Newbie
 
Registered: Jul 2012
Location: Columbus, OH
Distribution: Centos 6.3
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by beroteme View Post
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. :-/

Last edited by mmorton89; 09-28-2012 at 07:34 PM.
 
Old 10-02-2012, 06:08 AM   #10
beroteme
LQ Newbie
 
Registered: Sep 2012
Distribution: nix
Posts: 2

Rep: Reputation: Disabled
@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.
 
Old 10-02-2012, 02:42 PM   #11
mmorton89
LQ Newbie
 
Registered: Jul 2012
Location: Columbus, OH
Distribution: Centos 6.3
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by beroteme View Post
@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.
 
Old 10-03-2012, 12:21 AM   #12
jsaravana87
Member
 
Registered: Aug 2011
Location: Chennai,India
Distribution: Redhat,Centos,Ubuntu,Dedian
Posts: 558
Blog Entries: 5

Rep: Reputation: Disabled
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

Last edited by jsaravana87; 10-03-2012 at 12:24 AM.
 
Old 10-08-2012, 12:52 PM   #13
mmorton89
LQ Newbie
 
Registered: Jul 2012
Location: Columbus, OH
Distribution: Centos 6.3
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by arun5002 View Post
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.
 
Old 10-09-2012, 12:11 AM   #14
jsaravana87
Member
 
Registered: Aug 2011
Location: Chennai,India
Distribution: Redhat,Centos,Ubuntu,Dedian
Posts: 558
Blog Entries: 5

Rep: Reputation: Disabled
Hi

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


#chkconfig mysqld resetpriorities
 
Old 10-09-2012, 02:39 AM   #15
slavash
LQ Newbie
 
Registered: Sep 2012
Posts: 3

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] chkconfig --add doesn't let me add x201s Linux - Newbie 2 03-14-2011 09:47 PM
[SOLVED] chkconfig: cannot add new service. deostroll Linux - Server 5 03-09-2010 01:09 AM
chkconfig --add auditd mccartjd Linux - Newbie 6 05-21-2008 03:28 PM
chkconfig --add noir911 Linux - General 3 11-23-2006 01:26 AM
How do I add a program to the chkconfig --list? hunterhunter Linux - General 1 04-12-2006 05:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration