Restarting / Starting Processes Automatically?

OliverScott

Verified User
Joined
May 4, 2007
Messages
57
Two questions (general linux rather than specifically DA) that I hope someone can help me with:

1) I have fetchmail set up to collect email from a couple of POP3 ISP accounts and pass it on to exim etc. When I restart the server I have to manually start this as a daemon using the command "fetchmail -d 600". What is the best way to get this to run automatically on startup? I tried messing with inittab and rc.local but didn't get it to work.

2) SpamAssassin has a nice bug which causes spamd to disappear every few days. Is there any whay to automatically restart processes when they fail?

Thanks!
 
Use chkconfig to start services at the boot time. About spamd - just add "spamd=ON" to /usr/local/directadmin/data/admin/services.status.
 
OliverScott, did your rc.local file include the complete path to fetchmail? If it includes the complete path, it should work.

Jeff
 
Cheers for the pointers - had been trying lots of stuff for hours without success!

I do have to admit though that I was a bit lost with chkconfig until I found a page with a suitable fetchmail script to put in init.d - which led me to another page, which led me to a method of writing a process monitor, which I have used in the end to deal with both problems.

So I didn't use your suggestions exactly, but wouldn't have found my solution without your initial help!! Thanks :)

First I edited the direct admin cron job:
vi /etc/cron.d/directadmin_cron

And added the following line designed to run every 5 minutes:
*/5 * * * * root /etc/mail/spamassassin/sa-restart

Then I created the sa-restart file:
cd /etc/mail/spamassassin
vi sa-restart

The contents of which was:
#!/bin/sh
COUNT=`ps ax | grep -v grep | grep -c spamd`
if [ $COUNT -eq 0 ]; then
# Send an e-mail warning spamd was down
echo -e "Subject: spamd is down.\n\n" | /usr/sbin/exim [email protected]
# Attempt to restart spamd
/usr/bin/spamd -d -c -m 5

sleep 10

COUNT=`ps ax | grep -v grep | grep -c spamd`
if [ $COUNT -eq 0 ]; then
echo -e "Subject: spamd not restarting.\n\n" | /usr/sbin/exim [email protected]
fi
fi
exit 0;

Then made the file executable:
chmod 755 sa-restart

Have just finished testing it (as well as a nearly identical script to handle fetchmail) and they seem to be working fine so far....
 
Remember that rc.local isn't running from a logged in user, so it doesn't have a default path. ;)

Jeff
 
Back
Top