On Sat, Jun 24, 2006 at 12:10:01PM -0400, Micah Anderson wrote:
 
> Have you tried redirecting stdout to a file in your cron/at job? Can you
> please provide a copy of the cronjob or atjob that causes this problem?
 
It's been more than 9 months since I first reported the problem so I
don't remember all details about the situation then--but as Yitzhak
notes, redirecting stdout and stderr did not make things work.  I'm not
in a position to reproduce the problem right now, but I do know that the
seeders get started when I run the cron job manually but not when it's
run by cron.

I'm attaching my cron file.  It's part of some home-rolled packaging I
set up.  Note that it redirects both stdout and stderr.


Jeroen

#! /bin/sh
# Keep download torrents for project ISO images up to date

BASEDIR=/srv/ftp/software
PROJECTS=`cat /etc/SIPAprojects`
DOWNLOADURL="http://thaiopensource.org/download/software";
NUMERICIP="61.19.242.42"
ANNOUNCEURL="http://thaiopensource.org:6969/announce";
MINPORT=10000
MAXPORT=60000
BTUSER=bittorrent
DOWNLOADSTATEDIR=/var/run/bittorrents
LOGDIR=/var/log/bittorrent

ensuredir () {
        DIR="$1"
        if ! test -d "$DIR" ; then
                mkdir -p -- "$DIR"
                chown "$BTUSER" "$DIR"
        fi
}

if test -e /etc/default/btseed ; then
        . /etc/default/btseed
fi


ensuredir "$DOWNLOADSTATEDIR"
ensuredir "$LOGDIR/downloaders"

cd "$BASEDIR"

# PID file name for project $1
pidfile () {
        echo "$DOWNLOADSTATEDIR/$1-download.pid"
}

# Print PID for running downloader
pidfor () {
        PIDFILE=`pidfile "$1"`
        if test -e "$PIDFILE" ; then
                cat "$PIDFILE"
        fi
}

log_for () {
        echo "$LOGDIR/downloaders/$1.log"
}

# Return true if downloader for given project exists
downloader_running () {
        PID=`pidfor "$1"`
        if test -z "$PID" ; then
                /bin/false
        else
                ps "$PID" >/dev/null 2>&1
        fi
}


# Stop downloader for project $1
stopdownload () {
        PROJECT=$1
        PIDFILE=`pidfile "$PROJECT"`
        LOGFILE="`log_for "$PROJECT"`"
        echo -n "Stopping downloader... " >>"$LOGFILE"
        date >>"$LOGFILE"
        /sbin/start-stop-daemon --quiet --oknodo --pidfile "$PIDFILE" --user 
"$BTUSER" --stop
        rm -f "$PIDFILE"
}


# Start downloader for project $1 (in directory ./$1), torrent file $2
startdownload () {
        PROJECT="$1"
        ISONAME="$2"
        TORRENT="$3"
        PIDFILE=`pidfile "$PROJECT"`
        LOGFILE="`log_for "$PROJECT"`"

        pushd "$LOGDIR/downloaders" >/dev/null
        echo -n "Starting new downloader for $PROJECT: "
        echo -n "Starting downloader... " >>"$LOGFILE"
        date >>"$LOGFILE"
        su - "$BTUSER" <<EOF
            /usr/bin/nohup /sbin/start-stop-daemon --pidfile "$PIDFILE" \
                --make-pidfile \
                --nicelevel 10 \
                --user "$BTUSER" \
                --start \
                --exec /usr/bin/btdownloadheadless \
                -- \
                --display_interval 600 \
                --ip "$NUMERICIP" \
                --bind "$NUMERICIP" \
                --minport "$MINPORT" \
                --maxport "$MAXPORT" \
                --super_seeder 1 \
                --url "$DOWNLOADURL/$PROJECT/$TORRENT" \
                --saveas "$BASEDIR/$PROJECT/$ISONAME" >>"$LOGFILE" 2>&1 &
EOF
        echo "$PROJECT."
        popd >/dev/null
        
}


# Create torrent file $2 for project $1 (in directory ./$1) and start it
maketorrent () {
        PROJECT="$1"
        INFILE="$2"
        TORRENT="$3"

        DESC="Most recent $PROJECT CD image as of `date`"
        echo "Updating $TORRENT..."
        rm -f "$PROJECT/$TORRENT"
        btmakemetafile "$ANNOUNCEURL" "$PROJECT/$INFILE" --comment "$DESC"
        chgrp "$PROJECT" "$PROJECT/$TORRENT"
}


for p in $PROJECTS ; do
        ISONAME="$p-latest.iso"
        if test -e "$p/$ISONAME" ; then
                TORRENT="$ISONAME.torrent"
                CHANGED=`find "$p" -name "$TORRENT" -newer "$p/$ISONAME"`
                if test -z "$CHANGED" ; then
                        stopdownload "$p"
                        md5sum "$p/$ISONAME" >"$p/$ISONAME.md5sum"
                        maketorrent "$p" "$ISONAME" "$TORRENT"
                fi
                if ! downloader_running "$p" ; then
                        startdownload "$p" "$ISONAME" "$TORRENT"
                fi
        fi
done

Reply via email to