Hello,
I have a forum software on my server that has been having trouble accessing the mySQL database, which is hosted on a different server. The problems can be either too many connections or lost connection. In an effort to restart Apache on the web server (this process somehow reset the connection to the mySQL server), the host has setup some cronjobs to do that. The following is a list of the user cronjob (apparently the "service httpd restart" line has not been working and so they added (cd /root; ./newapachestart.sh 2>&1) also):
Code:
[root@vps ~]# crontab -l
#*/10 * * * * /root/chkload.sh
#59 */2 * * * /root/sendcheck.sh
# following is not working in case of httpd already in stop stat !! yes.. strange..
#*/15 * * * * service httpd restart
*/5 * * * * (cd /root; ./newapachestart.sh 2>&1)
and ./newapachestart.sh contains:
Code:
#!/bin/bash
CNT=`ps ax | grep -v grep | grep -c httpd`
if [ $CNT -gt 10 ]
then
echo $CNT;
echo 'Restarting HTTPD...'
killall httpd
killall httpd
killall httpd
/etc/init.d/httpd restart
fi
if [ $CNT -le 0 ]
then
/etc/init.d/httpd restart
fi
Can someone please explain to me the following:
1) What exactly does (cd /root; ./newapachestart.sh 2>&1) mean? I don't quite follow why we have to change directory to root, and what is this "2>&1" business.
2) What is going on in this ./newapachestart.sh file? I really have no idea of what it's doing.
3) Is there a way to setup a .ps file to test the connection to mySQL and only restart if the connection is lost? (like maybe pinging the mySQL server to test the connection)