You are not logged in.

#1 2009-01-30 05:59:57

MTsoul
Member
From: Vancouver, BC
Registered: 2008-08-14
Posts: 95
Website

[SOLVED] Start offlineimap as a daemon?

I just installed offlineimap so I can use mutt to view IMAP email. How can I start it as a daemon so it automatically syncs email upon login? I found an rtorrent daemon script on the forum and just changed it to offlineimap, but it has a few problems.

1. It does not work upon init. It works if I manually do /etc/rc.d/offlineimap start.
2. It does not stop at all, regardless of how I do it - either manually or automatically.

Anything I can do to get this working?

Thanks.

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

[ -z "$OFFLINEIMAP" ] && OFFLINEIMAP=/usr/bin/offlineimap
[ -z "$OFFLINEIMAP_USER" ] && OFFLINEIMAP_USER=oliver
[ -z "$OFFLINEIMAP_HOME" ] && OFFLINEIMAP_HOME=/home/oliver
[ -z "$OFFLINEIMAP_SOCKET" ] && OFFLINEIMAP_SOCKET=$OFFLINEIMAP_HOME/.socket
[ -z "$OFFLINEIMAP_LOCK" ] && OFFLINEIMAP_LOCK=$OFFLINEIMAP_HOME/.session/offlineimap.lock
[ -z "$OFFLINEIMAP_DTACH" ] && OFFLINEIMAP_DTACH="/usr/bin/dtach -n $OFFLINEIMAP_SOCKET -z"

case "$1" in
    start)
        stat_busy "Starting offlineimap"
        PID=`pidof -o %PPID $OFFLINEIMAP`
        if [ -z "$PID" ]; then
            [ -S $OFFLINEIMAP_SOCKET ] && rm $OFFLINEIMAP_SOCKET &> /dev/null
            [ -f $OFFLINEIMAP_LOCK ] && rm $OFFLINEIMAP_LOCK &> /dev/null
        fi
        /bin/su -c "$OFFLINEIMAP_DTACH $OFFLINEIMAP &> /dev/null" \
            $OFFLINEIMAP_USER
        if [ $? -gt 0 ]; then
            stat_fail
        else
            add_daemon offlineimap
            stat_done
        fi
        ;;
    stop)
        stat_busy "Stopping offlineimap"
        PID=`pidof -o %PPID $OFFLINEIMAP`
        [ ! -z "$PID" ] && kill -s INT $PID &> /dev/null
        if [ $? -gt 0 ]; then
            stat_fail
        else
            rm_daemon offlineimap
            stat_done
        fi
        ;;
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;
    *)
        echo "usage: $0 {start|stop|restart}"
esac
exit 0

Last edited by MTsoul (2009-02-04 08:10:21)

Offline

#2 2009-01-30 06:03:42

MTsoul
Member
From: Vancouver, BC
Registered: 2008-08-14
Posts: 95
Website

Re: [SOLVED] Start offlineimap as a daemon?

I just realized that offlineimap is a python script, and pidof definitely won't work for stopping it. But it still doens't explain why starting it upon init does not work. sad

Offline

#3 2009-01-30 06:08:44

SamC
Member
From: Calgary
Registered: 2008-05-13
Posts: 611
Website

Re: [SOLVED] Start offlineimap as a daemon?

Why not put it it your cron file?

Offline

#4 2009-01-30 06:17:31

MTsoul
Member
From: Vancouver, BC
Registered: 2008-08-14
Posts: 95
Website

Re: [SOLVED] Start offlineimap as a daemon?

Win.

Thanks that was one hell of a stupid question haha.

Offline

#5 2009-01-30 07:41:01

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [SOLVED] Start offlineimap as a daemon?

MTsoul wrote:

1. It does not work upon init. It works if I manually do /etc/rc.d/offlineimap start.

Have to ask, as you didn't mention it - did you add it to the rc.conf DAEMONS array?

Offline

#6 2009-02-04 08:10:05

MTsoul
Member
From: Vancouver, BC
Registered: 2008-08-14
Posts: 95
Website

Re: [SOLVED] Start offlineimap as a daemon?

Yeah I did. Oh well.

Offline

Board footer

Powered by FluxBB