Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Semi-automatic Upgrade script for servers
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
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Tue Mar 02, 2004 7:26 pm    Post subject: Semi-automatic Upgrade script for servers Reply with quote

I was just wondering and a tiny little idea just popped into my head.

I like to have my server auto upgrade the programs files. But i can't do that, becuase of gentoo's config files being replaced etc etc

So i was wondering and i think i found a suitable solution for servers.

My server is a personal server. only about 5 people altogether use it. In my own country. therefore it just doesn't get used during the night. So thats when i usually setup automatic tasks, such as emerge sync and virus update and scans etc etc

I also hate the fact that i neglect my server, and not bother upgrading it. So over a while it gets old and then when i am forced to upgrade the list of upgrade files are endless and it would be like reinstall again.

But my solution, which i believe a lot of people will like, integrates into portage very nicely.

Since recently they added the buildpkgonly feature to portage, why not make full use of it.

So i created a simple script as my solution:
Code:

emerge sync >/dev/null 2>&1
emerge -uUDp world
echo "emerge -uUD -B -O world  > /dev/null"
emerge -uUD -B -O world  > /dev/null
echo "emerge -uUD -B world  > /dev/null"
emerge -uUD -B world  > /dev/null


I saved this code in /usr/bin/UpgradePortage.sh
and then did:
Code:
chmod +x /usr/bin/UpgradePortage.sh


Then i setup cron to run this in the middle of the night, or (which is best time for me since i stay up most of the night) at around 5AM in the morning. 5am in the morning is garanteed to be a time when everyone will be sleep, who uses my server :)

The way it works, i believe, is very clever.
It first emerge sync's. Then emrerge pretends to upgrade (onyl upgrade) the world file.
Then it COMPILE ONLY those upgrade files.

While this is happening, becuase of the great feature of cron to send emails and stuff, to the root user. It will save all the text thats gets outputed into the email and send it to the root user.

Then the root user can check to see what files are needed for upgrade and upgrades them manually, using the --usepkgonly feature.
Obviously now the root user will have chance to pick which package he/she wants to upgrade and then use etc-updade to upgrade the config files etc etc.

No packages will be installed without the root users notice.

And there you go :D:D:D

a very simple, but very effective automatic upgrade solution for everyone to use :)

As always, bugs etc etc should be submitted here.

Obviously this is very basic. If anyone has any clever ideas of how to improve the script, then please let me know.
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router


Last edited by MooktaKiNG on Wed Mar 03, 2004 4:42 pm; edited 3 times in total
Back to top
View user's profile Send private message
Hackeron
Guru
Guru


Joined: 01 Nov 2002
Posts: 307

PostPosted: Tue Mar 02, 2004 7:40 pm    Post subject: Reply with quote

This is not a good method and can seriously break things..

You need to run etc-update afterwards and in some cases revdep-rebuild or follow instructions printed on script, I'm just thinking of a better way to update.

Would be nice if I could find an archive of all config versions, that way I find a config file identical to the signature of current config file, and if it was unchanged by the user, then there's no harm in auto updating it after making a backup, otherwise leave the update pending for etc-update.

Also, since instructions can be taken from backup, I'm just working on a little script to grep only the useful stuf (not the applying patch, etc stuff), and generate an html page with details about all updates + instructions. Probably going to base on the already make portage-info bash script.
Back to top
View user's profile Send private message
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Tue Mar 02, 2004 7:44 pm    Post subject: Reply with quote

You don't understand what this script is for.

I'm sorry, i'm not very good at explaining things.

This script does NOT install the programs.

It ONLY compiles it itno binary and then emails you about it.

If you want to install you would use --usepgkonly option in emerge to install the packages. This installtion would be quicker becuase the package is already in a compiled form and therefore saving the user a lot of time. Also the server does not get clogged up compiling some program, when its needed for other things.

Late at night, the server does nothing. Its the perfect time to make it do something, and compiling packages is a good deal.
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router
Back to top
View user's profile Send private message
Hackeron
Guru
Guru


Joined: 01 Nov 2002
Posts: 307

PostPosted: Tue Mar 02, 2004 8:38 pm    Post subject: Reply with quote

ah, I see now. Nice idea :) I was mislead by the thread title: Nice auto-upgrade tip for server and such

so it doesn't upgrade, just builds.
Back to top
View user's profile Send private message
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Tue Mar 02, 2004 8:51 pm    Post subject: Reply with quote

Yeh, i mind stops working when i drink lots of coffee.

Also i thought lets quickly type it up before i forget :D:D
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router
Back to top
View user's profile Send private message
malloc
l33t
l33t


Joined: 19 Sep 2003
Posts: 762

PostPosted: Tue Mar 02, 2004 8:54 pm    Post subject: Re: Nice auto-upgrade tip for server and such Reply with quote

MooktaKiNG wrote:

So i created a simple script as my solution:
Code:

emerge sync
emerge -uUDp world /* Shouldn't the output of this be redirected to a file so that the admin can see wich packages are going to get upgraded?
emerge -uUD --buildpkgonly world  >/dev/null 2>&1


Code:

emerge sync
emerge -uUDp world >> /path/to/somewhere/log.file
emerge -uUD -B world 2&>/dev/null

:?:
Back to top
View user's profile Send private message
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Tue Mar 02, 2004 9:03 pm    Post subject: Reply with quote

Please try and read carefully ;)

I said cron is a magical program that outputs everything that happened into an email and sends that to the root user.

So you would see all the output from "emerge sync", which i don't like to see, but i thought i'd include it. And you'll also see the output from emerge -uUDp world
The last command has >/dev/null 2>&1 to the end, which will make cron ignore the output, which is a pile load of compiling :D:D and you don't want to save all that to a file. too big.

trust me, this works fine. Just try it out. It won't b0rk your PC or anything. you can comment out the last command even. :D:D

I don't think people like simple solutions :D:D it scares people. :wink:
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router
Back to top
View user's profile Send private message
malloc
l33t
l33t


Joined: 19 Sep 2003
Posts: 762

PostPosted: Tue Mar 02, 2004 9:57 pm    Post subject: Reply with quote

I believe in you although my experience with cron says that it will only tell us something when whatever it was running went terribly wrong. :)
Just as a side note, how long have you been running this script?
It's just that i had a huge problem with putting emerge sync in cron. emerge was called in a linear inc way. 1,2,4,8...emerge processes were called simultaneously. I found that out when i had about 32 of them running at the same time and it totally brought my server to a complete halt :cry:
If you have it running and it hasn't given you problems i'm more than glad to try it out :)
Back to top
View user's profile Send private message
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Tue Mar 02, 2004 10:04 pm    Post subject: Reply with quote

Well i run many cron commands. I run emerge sync, since i installed my server, which would make it couple of months. Not every day though. Just every 3 days.

However, the script above would be more appropriate if people run it once a week, maybe during the weekend or something.

I can't say i have done any exntensive bug hunting. The code is simple enough and it should work. I'm running it right now. I even used it for few hours now, running every hour :D:D (turning emerge sync off). It seems to be working. It does email the root user.

However, i don't believe anything major will happen. I believe the worst that can happen is that cron didn't send an email, or the commands failed. In those cases, your gentoo won't get b0rked.

As always, i won't take responsibility of what the script will do. I can only tell you that it has worked for me.
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router
Back to top
View user's profile Send private message
webkiller71
n00b
n00b


Joined: 29 Nov 2003
Posts: 20

PostPosted: Tue Mar 02, 2004 11:45 pm    Post subject: Reply with quote

the only problem is, is that you won't get any notice if there was an error during the compile proces, and you should check if your harddisk doesn't get filled by all the packages
not that they will b0rk your system, but think of it
Back to top
View user's profile Send private message
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Wed Mar 03, 2004 12:40 am    Post subject: Reply with quote

Yeh i know. But you do get emailed. so therefore you know something was compiled, or compiled with error etc, then you checked the logs to see what happened. Then you can sort out all the binaries out your self.

I guess its very basic. I might try and improve it in the future :)
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router
Back to top
View user's profile Send private message
cschwede
n00b
n00b


Joined: 06 Sep 2002
Posts: 19
Location: Hamburg, Germany

PostPosted: Wed Mar 03, 2004 6:59 pm    Post subject: Reply with quote

Code:

#!/bin/bash
 /usr/bin/emerge sync > /dev/null
 for i in ` /usr/bin/emerge -pu --deep world | grep ebuild | cut -f 2- -d "/" | cut -f 1 -d " " ` ;
 do
         if [ -f /usr/portage/packages/All/$i.tbz2 ]
         then echo "Binary package $i existing, but it's not installed."
         else echo "Binary package $i doen't exist, emerging... "; /usr/bin/nice -n +19 /usr/bin/emerge -B =$i > /var/log/update.log
 fi
 done


Works like a charm for more than one year now.
Back to top
View user's profile Send private message
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Wed Mar 03, 2004 9:57 pm    Post subject: Reply with quote

Nice :D:D:D

I like that script.

I like it a lot :D:D:D

well, i did ask if anyone has better idea :D:D
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router
Back to top
View user's profile Send private message
bit
n00b
n00b


Joined: 23 Nov 2003
Posts: 34
Location: Dallas, TX

PostPosted: Thu Mar 04, 2004 8:25 pm    Post subject: Reply with quote

I was tryng to make my machine email me with what updates are available, I used this vcron line.

0 10 * * 2,5 emerge sync > /dev/null ; emerge -p world | sendmail bit

Odd because if I run that noramlly it works but when run by vcron it dosen't seem to do anything.
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