Showing posts with label restart. Show all posts
Showing posts with label restart. Show all posts

Monday, May 7, 2012

Script to check if mysql is alive and restart if its not.

The script below is done in Bash, which can be used across all Linux platforms. The function of the script is to check if mysql is currently running properly else it will restart the service.


1. Navigate to /root.
$ cd /root

2. Create a new file
$ vim mysql.sh
or
$ vi mysql.sh
Also give the command below to check the logs
$ touch /root/mysql.log

3. Insert the following lines to the file
-----------------------------------
#!/bin/bash
/usr/bin/mysqladmin ping| grep 'mysqld is alive' > /dev/null 2>&1
if [ $? != 0 ]
then
        /etc/init.d/mysqld stop
        /etc/init.d/mysqld start
        echo Starting at `date`
fi
-----------------------------------

4.  Give execute permission.
$ chmod 755  mysql.sh

5. Set a cron to check it at regular intervals.
$ crontab -e
*/5 * * * * sh -x mysql.sh
(This will check every 5 minutes)

Script to Check the load of webserver and Restart Services

The script below is done in Bash, which can be used across all Linux platforms. The function of the script is to check the web-server load and restart the normal services which reduces the load. It restarts apache and mysql. You can custom this to restart your services.

1. Navigate to /root.
$ cd /root

2. Create a new file
$ vim load.sh
or
$ vi load.sh

3. Insert the following lines to the file
-----------------------------------
LOAD=`uptime|awk '{print $10}'|cut -d, -f1 |cut -d. -f1`
if [ $LOAD -ge 50 ]
then
killall -9 mysqld
killall -9 mysqld
killall -9 mysqld
killall -9 httpd
killall -9 httpd
killall -9 httpd
for SEMID in `ipcs -s httpd| awk '{print $2}'| grep -iv sem`; do ipcrm -s $SEMID; done
/etc/init.d/httpd start
sleep 20
/etc/init.d/mysqld start
echo high load $LOAD at `date`, mysql/apache restarted >> /usr/monitor/mysql.log
fi
-----------------------------------

4.  Give execute permission.
$ chmod 755  load.sh

5. Set a cron to check it at regular intervals.
$ crontab -e
*/5 * * * * sh -x load.sh
(This will check every 5 minutes)

Friday, April 13, 2012

djbdns (TinyDns) not starting in Kloxo (Solved / fixed)

After switching from named to tinyDNS in kloxo. The djbdns is not working.
# /etc/init.d/djbdns restart
Stopping Djbdns:
Starting Djbdns:
# /etc/init.d/djbdns status
tinydns is stopped
Also tried to stop and start but still no luck.
 #service djbdns stop
Stopping Djbdns:
# service djbdns start
Starting Djbdns:
service djbdns status
tinydns is stopped

Check if the ip is entered correctly in the following file.
# echo "xxx.xxx.x.xx" >> /var/tinydns/env/IP; chattr +i /var/tinydns/env/IP
# cat /var/tinydns/env/IP
  xxx.xxx.x.xx

Also check if the path is correct in the files /usr/local/lxlabs/kloxo/file/djbdns.init and /etc/init.d/djbdns. Open each file and check the line
Qmailtcp=/usr/local/bin/tcpserver
In my case the location of tcpserver was /usr/bin/tcpserver. Hence i changed this to
Qmailtcp=/usr/bin/tcpserver
Note: Change this is both files.

Now login to kloxo and take Administration --> Servers --> localhost --> Services. Everything should be in green. :)


Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews