rsync SSH non standard port

Let’s assume that the ssh daemon from one of your remote servers is running on a non standard port, and you need to perform a rsync between your server (you are using the default port right?) and this machine. After some searching, the man page of rsync finally offered the magic solution to specify the SSH port, by using the -e parameter:

rsync -vrtz -e “ssh -p 22022” /other/similar/path/

-v = increase verbosity
-r = recursive
-t = preserve times
-z = compress file data during the transfer


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”

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
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

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

Plesk clear qmail queue

I will describe today how you can clear the queue for qmail, for a server that is running Plesk. First of all you should use one of the methods described with caution. The second method described is an automation of the first method and this is why I will include both of them. This method only removes the messages from the queue, and nothing else is lost.

First of all check the number of messages from the queue using the qmail-qstat tool:

[root@test /]# /var/qmail/bin/qmail-qstat
messages in queue: 22463
messages in queue but not yet preprocessed: 22

To remove the messages from the queue ALWAYS stop the qmail service first, to avoid having to reconfigure it again:

service qmail stop

Once the service is stopped execute the following commands one by one (based on the number of files stuck in the queue, this may take a while):

find /var/qmail/queue/mess -type f -exec rm {} \;
find /var/qmail/queue/info -type f -exec rm {} \;
find /var/qmail/queue/local -type f -exec rm {} \;
find /var/qmail/queue/intd -type f -exec rm {} \;
find /var/qmail/queue/todo -type f -exec rm {} \;
find /var/qmail/queue/remote -type f -exec rm {} \;

Finally start the mail service and recheck the queue to ensure that all the messages have been removed:

service qmail start

To automate this process I have two scripts available (basically are performing the same operations as above). For those that receive oversized file truncating errors please use the 2nd script – it takes a little longer but gets the job done.