Notification on server restart

Many times you find out that your server has been rebooted, but that information comes to late for you. For those cases, and not only, you can set a cron job that would sent a notification to your email address, each time when your server is rebooted. For this run first

crontab -e

(this opens up vi as your crontab editor) and at the end of the file add this command:

@reboot echo “`date +%r` `date +%b-%d-%Y` the server has been restarted.” | mail -s “`hostname` restart” dragos@fedorovici.com

This way each time when your server is restarted a notification is sent to your email address. The notification includes the hostname of the machine (in title) and the date when the server has been restarted (on body).

WARNING: mismatch_cnt is not 0 on /dev/md0

Recently I received (through the Plesk backup cron) several reports about a mismatch in synchronized block on md0 (/boot) device :

Cron run-parts /etc/cron.weekly
/etc/cron.weekly/99-raid-check:
WARNING: mismatch_cnt is not 0 on /dev/md0

Indeed the value for mismatch_cnt was nonzero:

[root@server ~]# cat /sys/block/md0/md/mismatch_cnt
128

First I went ahead and checked the status of the RAID, but cat /proc/mdstat was not returning any issues:

[root@server ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1] sda1[0]
264960 blocks [2/2] [UU]

md1 : active raid1 sdb2[1] sda2[0]
8193024 blocks [2/2] [UU]

md2 : active raid1 sdb3[1] sda3[0]
235737728 blocks [2/2] [UU]

To repair this I went ahead and forced the value of that block:

echo repair >/sys/block/md0/md/sync_action
echo check >/sys/block/md0/md/sync_action

Now the proper value is displayed for this block:

[root@server ~]# cat /sys/block/md0/md/mismatch_cnt
0