Managing Multiple Cooks

Marcel Gagné

Issue #84, April 2001

Marcel offers an intranet recipe called Grand Salmar Station.

Vien ici, François! Have a look at this. What do you mean, what is it? It is our new intranet. What do you think of it? Mon Dieu! You cannot tell me because you do not know what an intranet is? I am certainly glad our guests have not yet arrived, François. You know, working here at Chez Marcel, they naturally assume that you are an expert about these things.

An intranet, François, can be thought of as your own private Internet, a networked environment where users can share information, participate in discussions and use networking technologies to make getting to that information as easy as possible. It can be many things, really—a database providing access to corporate documents, an information center for job postings, a discussion board or a place to find the results of the latest hockey pool, non? An intranet is a place to share information. It can take many forms, but the essence of an intranet is a high-tech bulletin board, one that lets you post simple notices as well as entire multipage documents. Unlike that corkboard in most company lunchrooms, a good web-based intranet has virtually unlimited room.

François, why are you not looking at me when I talk to you? Ah! Mes amis. Welcome to my restaurant. François! To the cellar pour du vin. Vite! Bring back the 1990 Vosne-Romanée Les Beaux Monts. Nothing like a good Burgundy to discuss networks, non? Merci, François.

Please sit, mes amis. Before you arrived, I was showing François a special feature from this very restaurant. Although we love to bring you delicacies from around the world, sometimes it is our kitchens that do the creating, non? Sally Tomasevic, master chef, has written an intranet package we call Grand Salmar Station. What is really wonderful about this package is that it is virtually self-administering. A common problem with intranet solutions is that they require a technical person to oversee the project. At the very least, someone has to write HTML, maintain the structure and deal with dated information. Unfortunately, sometimes that person (and their dedication) can be hard to come by.

Ah, François, you have returned. Merci. Please pour for our guests. What if I told you, mes amis, that you could deploy an intranet and turn it over to your users and let them maintain it without having to train them? They would not need to know any HTML, and they would not have to code a single line. Chef Sally has created just such a package. It's even better. Grand Salmar Station will automatically create and maintain all links for you and will even expire old postings or dated information without you lifting a finger. Any newly added item will magically appear on the intranet's What's New page to highlight it. Normally, such adding and deleting requires user intervention and links must be verified and re-created. No problem with this intranet. It does it all for you.

It is a bulletin board, a flexible news center, an internet reference list, an office directory and a document management system, all in one. Best of all, Grand Salmar Station is freely distributed under the GPL.

Figure 1. Grand Salmar Station Front Page

For this recipe, you will need the following ingredients: a Linux System (but that goes without saying, non?), an Apache web server, Perl, PostgreSQL and the latest Grand Salmar Station source.

La Préparation

Grand Salmar Station is written completely in Perl and uses PostgreSQL as its database. You may recall PostgreSQL from past visits to the restaurant. Our menu has featured applications based on this excellent database, so you may already be quite familiar with it. It is possible that you even have it running as part of your day-to-day processes. In case you do not, I will give you a quick introduction. For the others, may I recommend a little brie while you wait? You will find cooking instructions for the intranet a little further on.

PostgreSQL is an advanced multiuser, relational database management system (RDBMS) distributed freely along with its source code. Originally written in 1985 and worked on by many developers worldwide, PostgreSQL is fast, powerful, supports most (if not all) SQL standards, and best of all, it is free. You probably don't even have to go looking for PostgreSQL since it is usually packaged as part of most major Linux distributions. Look on your distribution CD it is probably already there. In fact, on some systems, PostgreSQL is part of the default install making it that much easier.

Here at Chez Marcel, we enjoy cooking with open source, non? And we love working from source. So, for this recipe, we will be building PostgreSQL from the freshest of ingredients. The latest version is available by visiting the site at http://www.postgresql.org/, or as I mentioned mere moments ago, simply take it from your own distribution CD.

After downloading the latest bundle, I extracted it to a temporary location, changed directory to the source directory and compiled. Here are the steps:

tar -xzvf postgresql-7.0.3.tar.gz
cd postgresql-7.0.3/src
./configure
make
make install

The distribution directory (postgresql-7.0.3 in this case) has a nice INSTALL file that you might want to take a moment to read since there are some options related to the configure script that you might find useful. For instance, by default, PostgreSQL will install in the /usr/local/pgsql directory, and you may find that location less than palatable. Tastes vary.

When the compile is done, PostgreSQL will have to know how to find its libraries. You can always modify your environment variable to include /usr/local/pgsql/lib in the LD_LIBRARY_PATH, but it's probably easier to add the path to the /etc/ld.so.conf file. This is a text file that tells the system where to search for libraries. Because it is straight text, just add the path to your libraries and run this command as root:

ldconfig

If you decided to install a PostgreSQL binary from your CD, a postgres user will have been created as part of the installation. Otherwise, create a postgres user with its home directory being the PostgreSQL install directory. Then, assign a password to the user and log in as postgres. If you built your database along with me, you will be in the /usr/local/pgsql directory. Next step is to create a data directory:

mkdir data
To initialize the database for the first time, use the following command:
$ bin/initdb -D /usr/local/pgsql/data
That is, of course, the data directory that you just finished creating, n'est-ce pas?

You will see a number of messages going by as PostgreSQL reports on what it is doing. Not quite enough time for a full meal, but perhaps a single escargot and a sip from your wineglass, non? Meanwhile, some default permissions will be set. In addition, a default database will be created along with PostgreSQL's own database (pg_database) for user and other database information. Several views are then created after which you should get a message like this:

Success. You can now start the database server using:
/usr/bin/postmaster -D /var/lib/pgsql
    or
/usr/bin/pg_ctl -D /var/lib/pgsql start

Either will work, but the second is a better choice because it launches the process into the background for you. You will also want to add this to your startup for system boot.

Now, it is time to create some users that will have access to your database. If you are installing as root (for access to Perl directories, CGI directories, etc.), then root will have to be added, as will the user “nobody”. This is often the user that your httpd server runs as. Some have a user called “www” to run web services. I will use “nobody” as mine, and you may use whatever your server is configured for. Start by logging in as your postgres user, and execute the following commands to add users “root” and “nobody” to your PostgreSQL system:

$ createuser root

You'll be prompted for root's UID (accept the default) and whether user root is allowed to create databases. Answer “y”. When asked whether root is allowed to create users, I answered “y” again. Now, do the same thing for user nobody. The only difference is that I answer “n” to the question of whether nobody is allowed to create databases as well. Depending on which version of PostgreSQL you are using, the question of whether a user is allowed to create other users may be worded this way:

Is user whoever a superuser?
The answer is still “n” or “no”.

And Now, Your Perl Modules

Now, onto the Perl side of things. In order to make programming database access easier with Perl, the DBI modules were developed. DBI stands for Database Interface and consists of a collection of routines that offer standard hooks into an SQL database. DBD is an application program interface (API) for Perl 5 to interface with database systems. The idea is to provide a consistent set of modules and calls so that database access code is portable without too much fuss.

Now, since there are a number of database formats out there (PostgreSQL, MySQL, Sybase, Oracle, etc.), there will be some variance in accessing and talking to those various databases. This is where the DBD modules come into play. DBD are the Database Dependent modules. They are identified by the database they support by a simple suffix. For instance, DBD-Pg is the DBD module for PostgreSQL. Meanwhile, DBD-Informix is the DBD module for the Informix database.

Essentially, the DBI module is common to all the various databases, but the DBD module must be (and is) database-specific.

Downloading and Installing the Modules

Both the DBD and DBI module can be found at the CPAN FTP site, a huge Perl resource on the Web. Because the two modules are in slightly different directories, I will give you both starting with the DBI module. See ftp://ftp.cpan.org/CPAN/modules/by-module/DBI/.

The DBD module can be found at the CPAN site at ftp://ftp.cpan.org/CPAN/modules/by-module/DBD/. At the time of this writing, the latest and greatest DBI version was DBI-1.14, whereas the DBD release number was DBD-Pg-0.95. It probably makes sense to get the latest and greatest when it comes to these modules, particularly if you are using the latest PostgreSQL. The reason for this is that the modules grow and develop with the databases they reference. The most recent PostgreSQL database is best served by the most recent DBD-Pg.

Install the DBI module first by unpacking the distributions into some temporary directory and following these steps:

cd /usr/local/temp_dir
tar -xzvf DBI-1.14.tar.gz
cd DBI-1.14
perl Makefile.PL
make
make test
make install

To install the DBD module, the process is similar. Please note that more recent versions of the DBD module now require you to set a couple of environment variables before the install can occur. These are POSTGRES_LIB and POSTGRES_INCLUDE:

export POSTGRES_LIB=/usr/local/pgsql/lib
export POSTGRES_INCLUDE=/usr/local/pgsql/include
Now, you can run the install:
cd /usr/local/temp_dir
tar -xzvf DBD-Pg-0.95.tar.gz
cd DBD-Pg-0.95
perl Makefile.PL
make
make test
make install

Installing the Intranet Software

Ah, la pièce de résistance. Start by downloading the latest release from the Salmar web site at http://www.salmar.com/gss/. Then, extract it into a temporary directory. Once again, it comes with a lovely little README file that you may want to indulge in. For the impatient, this is all you do:

tar -xzvf sciintra.tar.gz
cd installintra

Before we begin the actual install, we must pause and modify one little configuration script. This is a small text file called sciintra_conf.pl, and you can edit it with your favorite text editor. Here is what you will find in the file.

Listing 1. Contents of sciintra_conf.pl

The first thing to do is make sure that the path to your Perl executable is correct. It will either be /usr/bin/perl or /usr/local/bin/perl. Now, go down to the last three lines and fill in the path to your Apache server's document root and cgi-bin directory. What you see above is the file's default configuration. If this fits your own system configuration, then you don't have to change anything.

Now, it is time to finish our install:

./install

Right away, the script does a couple of sanity checks, specifically to make sure that you have PostgreSQL running and Perl installed. Once satisfied, it will ask you an interesting little question:

Do you also wish to install the phonebook (Y/N) ?
A call for you, perhaps? Can you hear the music, mes amis? Ah, memories. Think back to the June 2000 issue of Linux Journal. Chez Marcel's little kitchen turned up an intranet telephone book for the “Who's Who in Linux?” issue. Well, if you have our little phonebook installed, then you can reply with an “N” for no, otherwise, why not install this wonderful little phonebook? It will then be available from the Grand Salmar Station Intranet menu, and it will be wonderful, like this lovely little Syrah. Pardonner moi while I have a little sip. Ah, wonderful.

Next, you will be asked whether you wish to install the intranet. Well, mes amis. That is why we are here, non? Just respond with a “Y”. The install then calls a Perl script to do the rest of the installation. You are almost done, mes amis. One more thing.

As I mentioned in the introduction, Grand Salmar Station can automatically clean up after itself. If you decide to post a date-sensitive item, the software can automatically remove this item from the intranet after a specific date. To activate this feature, add the following command to run with cron:

/usr/local/apache/cgi-bin/scimaint/dailyclean.pl

You may, if you wish, copy it to some other location. We will discuss the security aspects of the administrator shortly.

Working with the Intranet

There are two different faces to the intranet. What everyone else sees and has access to and a few little items strictly for the administrator's eyes. The administrator's menu is available via your favorite browser at http://yourmachine_name/scimaint/admin/.

From here, you can set various configuration parameters. The first option allows you to create, modify or remove posting categories. You'll see that as “Update Categories” on the menu. The Posting Category Heading is what your users will see when they look at the public face of the intranet. The default category is “News”, but you can set it to documents. News items will show up in the user menu under “All the News” while documents will show up under “All the Documents”. Both will appear briefly in the “What's New” menu, but you can decide to override that default at this point.

You can also define who is allowed to post here. Your choice is between allowing only administrators or making it a public category and letting everyone have a go. Have a look at Figure 2 for a special category created by your chef.

Figure 2. Creating Posting Categories

Another choice you have at this point is whether to allow internet links. Links can refer to sites anywhere else on the Internet, internally, or for that matter, company documents somewhere on your local network. You can then decide on posting order: whether alphabetically or by date, ascending or descending. Finally, you specify whether the system will take care of expiring and removing these links automatically.

Grand Salmar Station offers many other options. For instance, you can change the style of the intranet—in essence, the look and feel of it. You will find six styles included with the distribution with such exotic names as “Beach Time”, “Copper Kettle” and “Blue Skies”. Mais oui, of course you can create your own. Any style you choose can then be propagated across your entire intranet.

The phonebook can also be administered from here (if you chose to install it) as can other intranet defaults like expiration dates. Explore. Enjoy. And, bien sur, be sure to read the accompanying documentation, also available from the Administrator's menu.

If you want to get a feel for what a user will see, use http://yourmachine_name/scimaint/admin/demoreset.html to generate a demonstration database along with some sample entries. Ah, oui. The users—they have their own path into the intranet: http://yourmachine_name/sciintranet/.

Have a look at Figure 3 for a peek at their “What's New” screen.

Figure 3. What's New on the Intranet?

Mon Dieu, mes amis. It is late, non? François, please, refill our guests' wineglasses before they go! I hope, mes amis, that you will enjoy working with our intranet. Sally and I are quite proud of it, and we hope you will find it useful as well. In the meantime, I must thank you for coming tonight. Finish your wines, relax and make sure you join us next time at Chez Marcel. Your table will always be waiting.

A votre santé! Bon appétit!

Resources

Marcel Gagné lives in Mississauga, Ontario. In real life, he is president of Salmar Consulting, Inc., a systems integration and network consulting firm. He is also a pilot, writes science fiction and fantasy and is coeditor of TransVersions, a science fiction, fantasy and horror anthology. He loves Linux and all flavors of UNIX and will even admit it in public. In fact, he is currently working on Linux System Administration: A User's Guide, coming soon from Addison-Wesley Longman. He can be reached via e-mail at mggagne@salmar.com. You can discover lots of other things from his web site at http://www.salmar.com/marcel/.