Hello all,
I've been working on a set of build scripts for courier imap, in hopes that I can get it usable enough to post to the mailing list for further work and review.
So because I need to have a lot of mail generated, and fetched for testing purposes, I found that I need fetchmail running as a daemon for my testing.
Since Slackware does not come with a daemon for fetchmail, and yes I know that cron can do it, but that's another issue, I set out to write one for my testing purposes.
If I can get this to be reviewed by others I can put it on Slackwiki or perhaps send it to Mr. V for it to be added (if he wants) to /usr/doc/fetchmail/contrib or the like.
Any how, here's what I've got so far, and it does indeed work.
The only issue, is that when you do something such as "ps aux |grep fetchmail" it will only show "204" instead of the user 'fetchmail' due to posix requirements of a username less that 8 characters.
How to set up user and group info is at the end.
Please scrutinize it, rip it apart, yet at me, it's all good
Ok here's the code:
Code:
#!/bin/sh
INTERVAL=30
CONFIG=/etc/fetchmailrc
case "$1" in
start)
if [ -e /var/run/fetchmail/.fetchmail.pid ]; then
echo
echo "The fetchmail daemon appears to be running by the presence \
of /var/run/fetchmail/.fetchmail.pid."
echo
echo "To resolve this, try: fetchmail -quit or simply rm \
/var/run/fetchmail/.fetchmail.pid"
echo
echo "Start command failed: exiting now"
echo
exit
fi
echo "Starting fetchmail with uid/gid pair of `id fetchmail`"
# add the -v after CONFIG to get verbose output
# add the --invisible option to stop fetchmail adding itself to the headers
su - fetchmail -s /bin/bash -c "/usr/bin/fetchmail -L /var/log/fetchmail -d \
$INTERVAL -f $CONFIG -v --invisible"
echo "fetchmail: starting at `date`" >> /var/log/fetchmail
;;
stop)
echo "Stopping fetchmail"
su - fetchmail -s /bin/bash -c "/usr/bin/fetchmail -quit"
echo "fetchmail: stopped at `date`" >> /var/log/fetchmail
echo "" >> /var/log/fetchmail
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
# slackware commands to add fetchmail user and group
#groupadd -g 204 fetchmail
#useradd -u 204 -d /var/run/fetchmail -s /bin/false -g fetchmail fetchmail
# create fetchmails home:
#install -d -o fetchmail -g fetchmail -m700 /var/run/fetchmail
# create our config file template
#touch /etc/fetchamilrc <------------- if you don't have one already there
#chmod 600 /etc/fetchamilrc
#chown fetchmail:fetchmail /etc/fetchmailrc <------------if you dont have one there already
# crate the log file for fetchmail to use
#touch /var/log/fetchmail
#chown fetchmail:fetchmail /var/log/fetchmail
#chmod 600 /var/log/fetchmail