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 :-/ |
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..?
|
Quote:
Code:
### BEGIN INIT INFO |
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
|
Quote:
|
What about Should-Start:
|
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. |
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.
|
Quote:
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. :-/ |
@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. |
Quote:
Here is the output of chkconfig Code:
[root@server ~]# chkconfig Code:
[root@server ~]# cd /etc/init Code:
[root@server init.d]# cd /etc/rc2.d |
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:
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:
|
Quote:
I tried to manually rename the files as in.. Code:
mv S64mysqld S50mysqld |
Hi
To enable mysqld with low priority you have execute the below cammandline #chkconfig mysqld resetpriorities |
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. |