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):
[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:
CNT=`ps ax | grep -v grep | grep -c httpd`
if [ $CNT -gt 10 ]
echo 'Restarting HTTPD...'
if [ $CNT -le 0 ]
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)