2004-12-20

Installing and configuring CUPS


In my new office, most of the workstations are NT/2000 boxes on a separate LAN (called CH2M), while there are a few development machines on a separate LAN (called OSE). The two networks can talk to each other via the host Matrix (Linux 2.4.18-14), which also has Samba (2.2.5) installed on it.

There is a network printer (LaserJet 4050 TN), among others, available for printing.

I wasn't sure how good (or bad), the queue managing aspects of the printer were, and besides, I wanted to be able to view the jobs in the queue, pause and/or cancel them, if necessary.

Since Matrix was the gateway and also used as a server for other purposes (it has Oracle 9i and other such stuff), I decided to configure printing on it. Quick search on google revealed CUPS (www.cups.org) as the most-used and robust choice.

So I downloaded CUPS (version 1.1.22), and installed it. Below are the steps I followed:

Installing CUPS:

(make sure you have the following libraries installed before you start)
  • JPEG 6b or higher
  • PNG 1.0.6 or higher
  • TIFF 3.4 or higher
  • ZLIB 1.1.3 or higher


Installation is quick and easy:
  1. ./configure
  2. make
  3. make install

This installs the libraries at /usr/local/libs. The cupsd daemon is installed in /usr/sbin, while the startup script is installed in /etc/init.d/cups and the as usual, the config files go in /etc/cups

Configuring CUPS
1. Edit /etc/cups/cupsd using your favourite editor.

Servername - This is the name as advertised to the world. Clients of your CUPS server will see this name. In my case, it is set to:

ServerName matrix.ukose.com


AccessLog - This is the location of the CUPS access log (alike Apache). I didn't change it.

AccessLog /var/log/cups/access_log


LogLevel : controls the number of messages logged to the ErrorLog file and can be one of the following:
  • debug2 Log everything.
  • debug Log almost everything.
  • info Log all requests and state changes.
  • warn Log errors and warnings.
  • error Log only errors.
  • none Log nothing.


LogLevel debug


(Since I wanted to debug my CUPS setup, I changed the LogLevel to debug. Default is info).

Ports/addresses. The default port 631 is reserved for the Internet Printing Protocol (IPP) and is what we use here. You can have multiple Port/Listen lines to listen to more than one port or address, or to restrict access:

NOTE: In order for the command-line and web interfaces to work, you must have at least one Port or Listen line that allows access from the local loopback address (localhost).


Port 631


Scroll down now to the "<Location />" section. Alike Apache's httpd.conf, we need to specify connections from which network/subnet/IP can be made. I changed mine to allow connections from my local network:


Order Deny,Allow
Deny From All
Allow From 192.168.1.*


Finally, onto managing administration access. You may not want to configure/manage CUPS remotely, but from within the network, hence:


## Restrict access to local domain
Order Deny,Allow
Deny From All
Allow From 192.168.1.*


That's it. That's all we need to configure for now. Save the file and exit from your editor.

The next step is to add the printer to CUPS. Before you can add a printer to CUPS, you need to get the PPD file for your printer. The one-stop resource for Linux printing is www.linuxprinting.org. Check the printer listing page to see if your printer is listed (http://www.linuxprinting.org/printer_list.cgi). Mine is HP LaserJet 4050 TN. Following is what I was suggested:



HP LaserJet 4050
BW laser printer, max. 1200x1200 dpi, works Perfectly
Recommended driver: Postscript (Home page, manufacturer-supplied PPD



So then, I don't really need to download the manufacturer-supplied PPD according to CUPS. So, I'm just going to use the web-interface to add a printer. Alternatively, I could also use the command line. We'll explore both options :-)

As usual, web-interfaces are easy. CUPS web-interface is located at: http://localhost:631. It asks for a username/password. Enter "root" (without the quotes of course), and your root password (alternatively, you can modify cupsd.conf to enable more users to manage CUPS).
  1. Click "Add Printers"
  2. Specify the Name, Location and Description. Name is what the users will see, while Location and Description are friendly strings for users to identify the printer.
  3. You'd then need to specify the device for your printer. Most printers these days support Internet Printing Protocol (or IPP), so select that
  4. The next screen asks for the device URI. For IPP printers, it is of the form: socket://IP:port, with 9100 as the default port. So, for example, the device URI for my printer is: socket://192.168.1.2:9100
  5. It would then ask for the model/drive for your printer.

That's it. That's all you have to do to setup your printer through the web-interface.

Via, the command line, the CUPS command to use is lpadmin:

You can add a network printer enable the printer with:

# lpadmin -p hplj -v socket://192.168.0.6:9100/ -E

Another example for a LPD print server:


# lpadmin -p lp1nd -v lpd://printhost/lp1nd -E


To add information about the Location and a Description of the printer:


# lpadmin -p lp0 -L "Level 2 South" -D "HP LaserJet 4"


To specify a PPD for the printer:


# lpadmin -p lp7 -P /usr/share/postscript/ppd/HP_LaserJet_4050_Series.ppd
# lpadmin -p lp11 -P LEXC750.PPD


The PPD file is copied into /etc/cups/ppd/lp11.ppd, for example.

Lets now start cups.

Starting up cups is a simple matter:


[root@matrix sbin]# /etc/init.d/cups restart
cups: restarted scheduler. [ OK ]


Now that cups is started, let have a look at the logs to see what's happening:


[root@matrix sbin]# tail /var/log/cups/error_log
I [20/Dec/2004:11:39:02 +0000] LoadPPDs: Read "/etc/cups/ppds.dat", 16 PPDs...
I [20/Dec/2004:11:39:02 +0000] LoadPPDs: No new or changed PPDs...
D [20/Dec/2004:11:39:02 +0000] StartListening: NumListeners=1
D [20/Dec/2004:11:39:02 +0000] StartListening: address=00000000 port=631
D [20/Dec/2004:11:39:02 +0000] ResumeListening: setting input bits.


So, no apparent problems there. Let's now use the web-interface to print a test page. Voila, it works!

Ok, I wish it was that easy. You'd probably get the following in your logs:

var/log/cups/error_log
-----------------------
/Dec/2004:17:22:15 +0000] [Job 20] 0 %%+ font Courier-Bold
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%+ font Courier
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%+ font Symbol
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%EndComments
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%BeginProlog
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%BeginResource: font Courier-Bold
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%CreationDate: Wed Dec 22 1999
D [17/Dec/2004:17:22:15 +0000] [Job 20] Running /usr/local/bin/gs -dQUIET -dDEBUG -dPARANOIDSAFER -dNOPAUSE -dBATCH -dNOMEDIAATTRS -sDEVICE=cups -sstdout=%stderr -sOUTPUTFILE=%stdout -c -
D [17/Dec/2004:17:22:15 +0000] [Job 20] ESP Ghostscript 7.07.1: Can't find initialization file gs_init.ps.
E [17/Dec/2004:17:22:15 +0000] PID 5825 stopped with status 1!
E [17/Dec/2004:17:22:15 +0000] [Job 20] No pages found!
E [17/Dec/2004:17:22:15 +0000] PID 5826 stopped with status 1!
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%EndResource
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%BeginResource: font Courier
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%CreationDate: Wed Dec 22 1999
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%EndResource
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%BeginResource: font Symbol
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%CreationDate: Thu Oct 21 1999
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%EndResource
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%BeginResource: procset texttops 1.1 0
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%EndResource
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%EndProlog
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%Page: 1 1
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%Page: 1 1
D [17/Dec/2004:17:22:15 +0000] [Job 20] pw = 559.0, pl = 770.0
D [17/Dec/2004:17:22:15 +0000] [Job 20] PageLeft = 18.0, PageRight = 577.0
D [17/Dec/2004:17:22:15 +0000] [Job 20] PageTop = 806.0, PageBottom = 36.0
D [17/Dec/2004:17:22:15 +0000] [Job 20] PageWidth = 595.0, PageLength = 842.0
D [17/Dec/2004:17:22:15 +0000] [Job 20] 0 %%Trailer
D [17/Dec/2004:17:22:15 +0000] [Job 20] Saw Trailer!
D [17/Dec/2004:17:22:15 +0000] [Job 20] Saw EOF!
D [17/Dec/2004:17:22:15 +0000] UpdateJob: job 20, file 0 is complete.
D [17/Dec/2004:17:22:15 +0000] CancelJob: id = 20
D [17/Dec/2004:17:22:15 +0000] StopJob: id = 20, force = 0
D [17/Dec/2004:17:22:15 +0000] StopJob: printer state is 3


So, the culprit is ESP GhostScript fails to find the initialization file. This is one of the several install problems that exist in CUPS, and the install guide (according to me), is not clear enough. So, to get rid of this, you first need to have, yes you guessed it correctly! ESP GhostScript.

Download ESP GhostScript from http://www.cups.org/ghostscript.php.

So as you'd imagine, this is ghostscript customized/tweaked (I don't know the details) for CUPS.

IMPORTANT: Make sure you delete your old version of GhostScript, if any. I've found it causes numerous headaches.

GhostScript installation is easy (if you have the dependencies installed already), just follow the install steps.

Re-start CUPS once you have installed GhostScript, and you should have more success this time around.


CONFIGURING CLIENTS
Now that the printer has been configured and found working, we can proceed to adding the clients. There are two ways you can do that:

1. Manual - You can make your cups server listen for remote lpd connects by adding

# CUPS lpd support
printer stream tcp nowait root /usr/local/libexec/cups/daemon/cups-lpd
cups-lpd


to your inetd.conf

You then have to set up entries in /etc/printcap on the machines you want
to use the CUPS server. Annoying if it is lots of machines and/or lots of
printers.
2. Let CUPS do it for you

In cupsd.conf:

#
# BrowsePoll: poll the named server(s) for printers
#
BrowsePoll cups_server.example.com:631

You don't need to set up any printers on the client machines and any changes/new printers on the main CUPS server will automagically appear in the client printcap.


GENERAL PROBLEMS FACED:
1. Print jobs are aborted immediately
2. Ghostscript can't find initialization file gs_init.ps

In my experience, all problems were related to either the printed not being configured properly, or GhostScript not being installed. Any problems, feel free to email me at manavg<at>gmail.com

No comments:

Post a Comment