You need to login to send post. No account yet? Create one:
Create account
BASH Script to restart mailserver on VPS with Plesk panel
Thu, 09/01/2011 - 13:09
Keep VPS's services alive is crucial for any web designer. The problem is that usual shortage of RAM causing crashes almost on regular basis. On another place of this forum is published script which will restart Apache when necessary.
The second key part is a mailserver.
On Plesk is used Qmail mailserver with Courier service for POP3/IMAP. Therefore we can use simple BASH script to check it, and, if necessary, restart all Plesk services (which is actually easier than restart all services one by one). Save thish BASH script into /root/scripts folder, name it mail_restart.sh and give it an exec permission:
#!/bin/bash exists=`ps ax | grep -v grep | grep courier` if [ "$exists" = "" ] then /etc/init.d/psa stop /etc/init.d/psa start echo "Qmail stopped work, PSA have been restarted" | mail -s "Server Alert: PSA on VPS have been restarted" sentry@yourdomain.com exit fi
Next step is start this script regularly (once in 5 minuts should be OK) using CRON. As you have Plesk panel, you should use it under root account (or alternatively use command crontab -e) to add:
*/5 * * * * /root/scripts/mail_restart.sh >/dev/null 2>&1
OR... Combine this scripts into Webdesigner's combo :)
Script below is combination of Apache & mailserver restart script into one, which will watch all crucial services for you. Use it exactly in the same way as the single ones...
#!/bin/bash # Make sure you have these paths correct result=`/usr/bin/php /var/www/vhosts/yourserver.com/httpdocs/vpservercheck.php` service='courier' if ps ax | grep -v grep | grep $service > /dev/null then if [ $result != 1 ] then /etc/init.d/apache2 restart restartcheck=`/usr/bin/php /var/www/vhosts/yourserver.com/httpdocs/vpservercheck.php` if [ $restartcheck == 1 ] then echo "Apache on VPS have been successfully restarted!" | mail -s "Server Alert: VPS have been restarted" sentry@yoursite.com exit else echo "Restart of Apache on VPS has been unsuccessful!!!" | mail -s "Server Alert: VPS is in error state" sentry@yoursite.com exit fi exit fi exit else /etc/init.d/psa stop /etc/init.d/psa start echo "Qmail stopped work, PSA have been restarted" | mail -s "Server Alert: PSA on VPS have been restarted" sentry@yoursite.com exit fi


















