Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Automatically resuming an emerge on failure
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Rcomian
Apprentice
Apprentice


Joined: 10 Jan 2004
Posts: 174
Location: Uk, Northwest

PostPosted: Wed Jun 21, 2006 8:12 pm    Post subject: Automatically resuming an emerge on failure Reply with quote

Ok, so you've got several hundred packages to emerge. With the best will in the world, once you've got past the initial failures (missing ebuilds, masked packages, blockages) there's still going to be one or two failures when building that lot. The normal course of events for this is:
1. Start the emerge
2. Come back after 10 minutes and find it failed after 2
3. Fix the problem and resume
4. Come back 10 minutes later and find it failed on the next package
5. Ignore that package with a --resume --skipfirst and come back to it later
6. Repeat the above steps ad-nauseum
7. Fix up the packages that failed, doing research on forums, google, etc.

A resilient emerge script would allow you to walk away, come back when it's finished and examine any packages that failed to see if you could do anything about them.

With that I present the "Living Dead Emerge" script, it just keeps ploughing on nomatter what you throw at it:

Code:
#!/bin/sh

time=`date`
EMERGE_RESUME="" emerge $*
retry=$?

while [[ $retry -ne 0 ]]
do
    log=`genlop --nocolor --list --date "$time" | grep \>\>\> | awk -F ' >>> ' '{ print $2 }'`

    if [[ -n "$log" ]]; then
        # Command failed, but something was installed successfully, just try the command again
        echo "Trying again" 1>&2
        time=`date`
        EMERGE_RESUME="SAFE_MODE" emerge --resume
        retry=$?
    else
        # Command failed and nothing was installed since the last time emerge was run
        echo "Capturing failure" 1>&2
        time=`date`
        echo >>/var/log/portage_failures.output
        echo --------------- $time --------------- >>/var/log/portage_failures.output
       
        EMERGE_RESUME="SAFE_MODE" emerge --resume >>/var/log/portage_failures.output 2>&1

        if [[ $? -eq 0 ]]; then
            # Despite expectations, this succeeded
            exit 0
        else
            # See whether the resume actually managed to install something before failing again
            log=`genlop --nocolor --list --date "$time" | grep \>\>\> | awk -F ' >>> ' '{ print $2 }'`
            if [[ -z "$log" ]]; then
                echo "Resuming with next package" 1>&2
                EMERGE_RESUME="" emerge --resume --skipfirst
                retry=$?
            else
                # The resume installed the package that originally failed, then failed again on a subsequent
                # package - just go through an retry that package again
                retry=1
            fi
        fi
    fi
done


Use this script exactly as you would plain old emerge - you can see one of the first things it does is start emerge with the parameters you pass to the script.
If everything works through first time, then the script just exits and nothing new is done.
You can follow the script to see exactly what it does, but basically every failing package is tried 2 or 3 times, the last retry for a package logs all the output to a log file so you can see what failed and sort it out later, and we then carry on with the next package.

Simple, have fun!

Update
I've added in an EMERGE_RESUME variable so that any portage hooks can tell when they're installing a package which has previously had trouble, and perhaps take steps to prevent further failures. I'm thinking tmpfs type hooks, where the failure could be that the tmpfs directory was too small, if they find this variable set to non-empty, then they can NOT make a tmpfs, but just install on the normal slow hard disk.
Also you could install with ricer CFLAGS settings to begin with, and if the build fails (ok, the ebuild *should* filter them ...) then you can try more normal CFLAGS on the retry.


Last edited by Rcomian on Sun Jun 25, 2006 2:37 pm; edited 1 time in total
Back to top
View user's profile Send private message
killfire
l33t
l33t


Joined: 04 Oct 2003
Posts: 618

PostPosted: Thu Jun 22, 2006 4:13 am    Post subject: Reply with quote

wow. much better than my 'emerge foo || emerge --skipfirst foo || emerge --skipfirst foo...ad infinium'
_________________
my website, built in HAppS: http://dbpatterson.com
an art (oil painting) website I built a pure python backend for: http://www.lydiajohnston.com
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Thu Jun 22, 2006 8:23 am    Post subject: Reply with quote

My pye script can also do this for you.
_________________
shine on,

dr_strange

Set the Controls for the Heart of Gentoo
http://magenta.linuxforum.hu
Back to top
View user's profile Send private message
Rcomian
Apprentice
Apprentice


Joined: 10 Jan 2004
Posts: 174
Location: Uk, Northwest

PostPosted: Sun Jun 25, 2006 2:41 pm    Post subject: Reply with quote

dr_strange wrote:
My pye script can also do this for you.


Hmm, that page looks dead, is the script hosted elsewherer dr_strange?
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Mon Jun 26, 2006 12:59 pm    Post subject: Reply with quote

Rcomian wrote:
dr_strange wrote:
My pye script can also do this for you.


Hmm, that page looks dead, is the script hosted elsewherer dr_strange?


sorry, had a typo in the url :oops:

pye script --- now it should be fine
_________________
shine on,

dr_strange

Set the Controls for the Heart of Gentoo
http://magenta.linuxforum.hu
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum