Automation tools for a Gentoo Linux Network
At my place of work, I administer a small but growing network of servers and workstations, all based on either Gentoo Linux or Windows. I use Gentoo because I’m accustomed to it, I find the installation easy and straightforward, and I like being forced to take control of the setup of the systems.
Once you start getting more than a couple of Gentoo systems, however, running the update synchronization and other tasks can get a bit daunting. I’ll cover a list of ideas that I’ve implemented to make things a bit easier.
Set up a private Gentoo rsync server.
Since Gentoo uses rsync primarily to update the Portage tree (Portage being the source/package listings) it’s actually not difficult to designate one system to be your rsync server for your private network. This machine will then sync to the “Gentoo world”, and provide the same data to your local machines – saving bandwidth and making you a better “netizen”. It’s relatively simple to do.
- Add a cron job to the server to sync nightly
- Enable the rsync server for your “/usr/portage” directory.
- Add a cron job to the clients to sync to the server nightly (obviously leave enough time for your server to sync first!)
Once your systems are all syncing on their own, as time goes by they will need to be updated. You have a few options here.
Ways to Update
1. Write a simple script to automatically update.
This can be done with a simple script/command in your crontab that basically amounts to the “emerge -uD world” command.
This is a poor idea as certain packages may break software if you update…I have always felt updating needs to have user interaction…
So, another option is….
2. Set a script to email you a list of updates, then choose what to install via SSH
This is particularly useful if you have a lot of headless (i.e., no monitor) servers, and very simple to implement. You can use simple scripting and the SSMTP program to do it…and it’d basically look something like this:
**begin code**
#! /bin/bash echo "To: xxxx@xxxxx.com" > /opt/updatemail.txt echo "From: yyyy@yyyyy.com" >> /opt/updatemail.txt echo "Subject: $(hostname) Updates" >> /opt/updatemail.txt emerge -puD world >> /opt/updatemail.txt ssmtp -t </opt/updatemail.txt
**End Code**
As you can see, VERY simple coding. These are all commands you can type into the shell to test out for yourself: the most complex part is the “$(hostname)” which basically instructs the system to treat the output of the “hostname” command as a variable, thus we can see in the email subject which system is sending us it’s update list!
The ssmtp program, with the use of the “-t” option will automatically scan the text file you created with the script to set the To, From, and Subject for you so no interaction on the email side is needed. I used a Gmail account to allow ssmtp to have an SMTP server to login to when sending the mail.
3. Obviously, if you have a monitor connected to your systems, and the time, you can just go around punching in “emerge -puD world” and see what shows…
Simplifying the Update Process
If you use Gentoo, you know that much of it’s package management base relies on source code and that most things installed on a Gentoo system have to be compiled. This is okay for one, or even two systems, but it can get very frustrating after awhile. There are a couple of solutions to this….
1. Build a Distributed Compiling Cluster using DistCC
Installing and configuring DistCC is a relatively simple process, and once the “permitted hosts” functions are set, and the “hosts to use” option is set, you can have a rather nice P2P compile cluster established. DistCC is supported in Portage by using the “FEATURES=distcc” option in your /etc/make.conf file. Obviously, there’s still compiling involved but it can speed up the process and doesn’t require as much disk space as the next option.
2. Use pre-built binaries and build a binary repository
Portage has support for installing binaries, assuming you have a binary repository to point it at! Fortunately, it’s easy enough to make one. You can use the “-b” option with the emerge command to instruct the system to build a binary package simultaneously as it installs on the system. It will do this for all packages and dependencies installed during your use of the option.
This method works especially well if you are running systems all of the same architecture, however, you do (in my experience) lose some flexibility with the USE flags (these control how packages are compiled)…but if you are building similar machines this will not matter. You will need to set up an FTP or web-server to allow the other machines to access these binary packages which are, by default, stored in /usr/portage/packages. I use a cron job to move these packages to an external drive to allow more space…and I can take it mobile with me if I need to!
That’s it for now…hope this helps!
-Adam
