Hi, * Riccardo Stagni <[EMAIL PROTECTED]> [2006-07-31 21:15]: > On Mon, Jul 31, 2006 at 08:21:50PM +0200, Nico Golde wrote: > > Ok after discussing the issue with upstream I decided to > > take your initial method because fetchmail is able to decide > > itself how to deal with a wake-up when called correctly. > > Also if I like the signal based method alot more. > > :( > Also I preferred the signal based solution. > It has a lot of benefits: first of all it prints prettier logs!
[...] I attached a fixed version, please check its signal based. Regards Nico -- Nico Golde - JAB: [EMAIL PROTECTED] | GPG: 0x73647CFF http://www.ngolde.de | http://nion.modprobe.de/blog/ Forget about that mouse with 3/4/5 buttons - gimme a keyboard with 103/104/105 keys!
#!/bin/sh
#
# Fetchmail init script
# Latest change: Mo Jul 31 20:23:54 CEST 2006
#
# A fetchmailrc file containg hosts and passwords for all local users should be
# placed in /etc/fetchmailrc. Remember to make the /etc/fetchmailrc mode 600
# to avoid disclosing the users' passwords.
#
# This script will NOT start or stop fetchmail if the /etc/fetchmailrc file
# does not exist or /etc/default/fetchmail is set to no.
set -e
if [ ! -e /etc/fetchmailrc ]; then
exit 0
fi
test -f /etc/default/fetchmail || exit 0
. /etc/default/fetchmail
if [ ! "x$START_DAEMON" = "xyes" ]; then
echo "Edit /etc/default/fetchmail to start fetchmail"
exit 0
fi
# Defaults
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/fetchmail
USER=fetchmail
CONFFILE=/etc/fetchmailrc
PIDFILE="/var/run/fetchmail/fetchmail.pid"
OPTIONS="-f $CONFFILE --pidfile $PIDFILE"
UIDL=/var/lib/fetchmail/.fetchmail-UIDL-cache
test -f $DAEMON || exit 0
if [ "$1" = "start" ]; then
if [ ! -r $CONFFILE ] ; then
echo "$CONFFILE not found."
echo "can not start fetchmail daemon... consider disabling the script"
exit 0
fi
fi
# sanity checks (saves on MY sanity :-P )
if ! id $USER >/dev/null 2>&1; then
if [ "$USER" = "fetchmail" ]; then
# The fetchmail user might have been removed when the
fetchmail-common
# package is purged. We have to re-add it here so the
system-wide
# daemon will run.
adduser --system --ingroup nogroup --home /var/lib/fetchmail \
--shell /bin/sh --disabled-password fetchmail
>/dev/null 2>&1 || true
# work around possible adduser bug, see #119366
[ -d /var/lib/fetchmail ] || mkdir -p /var/lib/fetchmail
chmod 700 /var/lib/fetchmail
chown -h -R fetchmail:nogroup /var/lib/fetchmail
else
echo "$0: $USER user does not exist!"
exit 1
fi
fi
# add daemon option if user hasn't already specified it
if ! grep -qs '^[[:space:]]*set[[:space:]]\+daemon[[:space:]]' "$CONFFILE"; then
OPTIONS="$OPTIONS -d 300"
fi
# add syslog option unless user specified "set no syslog".
if ! grep -qs '^[[:space:]]*set[[:space:]]\+no[[:space:]]\+syslog' "$CONFFILE";
then
OPTIONS="$OPTIONS --syslog"
fi
# support for ephemeral /var/run
if [ "${PIDFILE%/*}" = "/var/run/fetchmail" ] && [ ! -d ${PIDFILE%/*} ]; then
mkdir /var/run/fetchmail
chown -h $USER:nogroup /var/run/fetchmail
chmod 700 /var/run/fetchmail
fi
# sanity check
#if [ ! -d ${PIDFILE%/*} ]; then
# echo "$0: directory ${PIDFILE%/*} does not exist!"
# exit 1
#fi
# If the user is going to use a UIDL cache, try to find a better place for the
# UIDL cache than root's homedir. Also create $UIDL if it doesn't exist,
# because the daemon won't have the permission.
if ! grep -qs idfile "$CONFFILE" && [ -d /var/lib/fetchmail ]; then
OPTIONS="$OPTIONS -i $UIDL"
touch $UIDL
chown -h $USER $UIDL
chmod 0600 $UIDL
fi
# Makes sure certain files/directories have the proper owner
if [ "`stat -c '%U %a' $CONFFILE 2>/dev/null`" != "$USER 600" ]; then
chown -h $USER $CONFFILE
chmod -f 0600 $CONFFILE
fi
case "$1" in
start)
if test -e $PIDFILE ; then
pid=`cat $PIDFILE | sed -e 's/\s.*//'|head -n1`
PIDDIR=/proc/$pid
if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" =
"${DAEMON}" ]; then
echo "fetchmail already started; not starting."
exit 0
else
echo "Removing stale PID file $PIDFILE."
rm -f $PIDFILE
fi
fi
echo -n "Starting mail retrieval agent: fetchmail"
if start-stop-daemon -S -o -q -p $PIDFILE -x $DAEMON -u $USER
-a /bin/su -- -c "$DAEMON $OPTIONS" $USER; then
echo "."
else
echo " (failed)."
exit 1
fi
;;
stop)
if ! test -e $PIDFILE ; then
echo "Pidfile not found! Is fetchmail running?"
exit 0
fi
echo -n "Stopping mail retrieval agent: fetchmail"
if start-stop-daemon -K -o -q -p $PIDFILE -x $DAEMON -u $USER;
then
echo "."
else
echo " (failed)."
exit 1
fi
;;
force-reload|restart)
echo -n "Restarting mail retrieval agent: fetchmail"
if ! start-stop-daemon -K -o -q -p $PIDFILE -x $DAEMON -u
$USER; then
echo " (failed on stop)."
exit 1
fi
sleep 1
if start-stop-daemon -S -q -p $PIDFILE -x $DAEMON -u $USER -a
/bin/su -- -c "$DAEMON $OPTIONS" $USER; then
echo "."
else
echo " (failed on start)."
exit 1
fi
;;
try-restart)
if start-stop-daemon -S -t -q -p $PIDFILE -x $DAEMON -u $USER
>/dev/null; then
exit 0
fi
$0 restart
;;
awaken)
echo -n "Awakening mail retrieval agent: fetchmail"
if [ -s $PIDFILE ]; then
start-stop-daemon -K -s 10 -q -p $PIDFILE -x $DAEMON
echo "."
exit 0
else
echo " (not running)."
exit 1
fi
;;
debug-run)
echo "$0: Initiating debug run of system-wide fetchmail
service..." 1>&2
echo "$0: script will be run in debug mode, all output to
forced to" 1>&2
echo "$0: stdout. This is not enough to debug failures that
only" 1>&2
echo "$0: happen in daemon mode." 1>&2
echo "$0: You might want to direct output to a file, and tail
-f it." 1>&2
if [ "$2" = "strace" ]; then
echo "$0: (running debug mode under strace. See
strace(1) for options)" 1>&2
echo "$0: WARNING: strace output may contain
security-sensitive info, such as" 1>&2
echo "$0: passwords; please clobber them before sending
the strace file to a" 1>&2
echo "$0: public bug tracking system, such as
Debian's." 1>&2
fi
echo "$0: Stopping the service..." 1>&2
"$0" stop
echo "$0: exit status of service stop was: $?"
echo "$0: RUNUSER is $USER"
echo "$0: OPTIONS would be $OPTIONS"
echo "$0: Starting service in nodetach mode, hit ^C
(SIGINT/intr) to finish run..." 1>&2
if [ "$2" = "strace" ] ; then
shift
shift
[ $# -ne 0 ] && echo "$0: (strace options are: -tt $@)"
1>&2
su -c "/usr/bin/strace -tt $@ $DAEMON $OPTIONS
--nosyslog --nodetach -v -v" $USER <&- 2>&1
else
su -c "$DAEMON $OPTIONS --nosyslog --nodetach -v -v"
$USER <&- 2>&1
fi
echo "$0: End of service run. Exit status was: $?"
exit 0
;;
*)
echo "Usage: /etc/init.d/fetchmail
{start|stop|restart|force-reload|awaken|debug-run}"
echo " start - starts system-wide fetchmail service"
echo " stop - stops system-wide fetchmail service"
echo " restart, force-reload - starts a new system-wide
fetchmail service"
echo " awaken - tell system-wide fetchmail to start a poll
cycle immediately"
echo " debug-run [strace [strace options...]] - start a debug
run of the"
echo " system-wide fetchmail service, optionally running it
under strace"
exit 1
;;
esac
exit 0
# vim:ts=4:sw=4:
pgpjkAtF80lup.pgp
Description: PGP signature

