Red Hat Linux 9 Professional Secrets [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Red Hat Linux 9 Professional Secrets [Electronic resources] - نسخه متنی

Naba Barkakati

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








Understanding the CUPS Printing System


In Red Hat Linux, with the CUPS printing system, the user’s view of printing is based on the basic printing commands:

lp ,

lpr ,

lpq ,

lprm , and

lpc status . A bit more information will help you understand how printing works behind the scenes. As with so many things in Linux, support for the CUPS printing system is all a matter of having the right files in the right places. This becomes apparent after you have configured Linux for networking and have set up dial-in modems, for example. In each case, you have to make sure that several configuration files appear in the correct places. The printing environment has the same requirement: configuration files that specify how printing occurs.

Although nowadays you can use graphical configuration tools to set up services such as printing and dial-up networking, it is useful to know the names of the text-configuration files because you can then fix problems even if you do not have access to a graphical login.

If you have experience with MS-DOS from a long time ago, you might have printed files by simply copying them to the printer port (LPT1, for example). You might think that a similar approach is good enough for Linux. As you see in the next section, such a brute-force approach to copying a file to the physical printer port is not appropriate for a multiuser system such as Linux. You need a way to queue print jobs and to have a separate printing process take care of the printing.


Copying to the Printer: Brute-Force Printing


If you have a printer connected to the

/dev/lp0 parallel port, you can print a text file simply by sending the file to the printer with the following command:

cat webstat.txt > /dev/lp0

This command indeed produces a printout of the file

webstat.txt , provided that the following conditions are true:



  • You are logged in as

    root (Linux allows only

    root and certain processes direct access to physical devices, such as printers).



  • The printer is connected to the /dev/lp0 port, powered up, and online.



The problem with copying a file directly to the printer device is that the command completes only when the copying (which, in this case, is equivalent to printing) is completed. For a large file, this process can take a while. In fact, if the printer is not turned on, the command appears to hang (if this happens, just press Ctrl-C to abort the command).


Printing the CUPS Way


On a multitasking and multiuser system such as Linux, a better way to print is to spool the data and schedule the printing: send the output to a file, and have a separate process send the output to the printer. That way, you can continue with your work while the printing takes place in the background. In addition, if your system has more than one user, everyone can print on the same printer, without worrying about whether or not the printer is available; the background printing process can take care of all the details.

That’s how the CUPS printing environment works. Users use a client program—lp or lpr—to send the files to be printed to a server called cupsd—the printer daemon—over a TCP/IP connection. The cupsd server then queues the files, filters the file (to get them ready for the printer), and sends them to the printer.

Although you typically have only one printer connected to your PC, one advantage of the CUPS printing system is the capability to print on a printer connected to another system on a network. Printing to a remote printer is handled in the same fashion as printing to a local printer; the local cupsd daemon simply sends the files to the remote system’s server.

As explained earlier, the user-level programs for spooling a file are lp and lpr. When lp or lpr runs, it sends the data to the cupsd server that manages the specified print queue. Other user-level commands for working with print queues are

lpstat ,

lpq ,

cancel ,

lprm , and

lpc . The program that completes the CUPS printing environment is the CUPS scheduler:

cupsd .

In addition to the commands

lpd ,

lpr ,

lpq ,

lprm ,

cancel , and

lpc , the configuration files in

/etc/cups directory play a crucial role in the CUPS printing environment. The “Understanding the CUPS Configuration Files” section describes the key configruation files.








Secret


A good way to understand CUPS is to take a look at the CUPS architecture—the parts that make up CUPS and how they fit together. CUPS is designed around the cupsd print scheduling process that accepts print jobs submitted through printing commands, spools print files, uses filters to convert filesto a form acceptable to the printer, and sends the data to printers using backends. Figure 4-8 shows the basic architecture of CUPS.


Figure 4-8: The CUPS Architecture.

As Figure 4-8 shows, the makor components of CUPS are as follows:



  1. CUPS Scheduler—cupsd is the scheduling process that acts as an HTTP 1.1 server and handles printing requests sent by clients using the Internet Printing Protocol (IPP). cupsd also acts as a Web server and provides a Web interface for administering CUPS print queues.



  2. Configuration Files—The configuration files in

    /etc/cups directory control how CUPS works. The “Understanding the CUPS Configuration Files” section further describes these files.



  3. Printing Commands—System V and BSD printing commands enable you to submit print jobs and check printer status from the command line.



  4. Filters—The filter programs located in the

    /usr/lib/cups/filter directory convert various input file formats (such as text, PostScript, and Image) into output understood by the printer on which the file is being printed. CUPS uses Ghostscript to convert PostScript page description language into output suitable for a specific printer.



  5. Backend—The backend programs located in the

    /usr/lib/cups/backend directory send the output of the filters to the destination printer. Each backend takes care of sending output to a specific type of connection such as locally connected parallel printer or a remote Windows printer that communicates with the SMB protocol.














Understanding the CUPS Configuration Files


You can learn a lot about the CUPS configuration files by examining the entries in various configuration files that the Red Hat printer configuration tool creates when you set up a new print queue. The CUPS configuration files are in

/etc/cups directory.

Consider the example of adding a new print queue named

Office-ES600 for an Epson Stylus Color 600 printer that is connected to the parallel port of the PC. Here are the files that contain information about this print queue and the printer model:



  • /etc/printcap—This file used to be the printer capabilities database and was very important to the LPD print spooler that used to be popular before CUPS came along (not that I miss LPD; CUPS is much better). CUPS generates single entry in the

    /etc/printcap file for each printer. For example, here is the

    /etc/printcap file that CUPS generates for a print queue named Office-ES600 (the details of the printer are in the

    /etc/cups/printers.conf file):

    # This file was automatically generated by cupsd(8) from the
    # /etc/cups/printers.conf file. All changes to this file
    # will be lost.
    Office-ES600:



  • /etc/cups/printers.conf—This is the printer configuration file with entries for each print queue. The information includes the device where the printer is connected and other parameters of the queue. Here is the entry for the Epson Stylus Color 600 printer:

    <DefaultPrinter Office-ES600>
    Info Created by redhat-config-printer 0.6.x
    DeviceURI parallel:/dev/lp0
    Location Epson Stylus 600
    State Idle
    Accepting Yes
    JobSheets none none
    QuotaPeriod 0
    PageLimit 0
    KLimit 0
    </Printer>



  • /etc/cups/cupsd.conf—This is the configuration file for cupsd, the CUPS print scheduler. The syntax of the configuration file is similar to that of Apache httpd, the Web server (see Chapter 14 for a description of Apache httpd configuration). The similarities with the Apache httpd configuration files are to be expected because cupsd is also an HTTP server. Here are the entries in

    /etc/cups/cupsd .conf for the print queue names Office-ES600:

    <Location /printers/Office-ES600>
    Order Deny,Allow
    Deny From All
    Allow From 127.0.0.1
    AuthType None
    </Location>
    <Location />
    Order Deny,Allow
    Deny From All
    Allow From 127.0.0.1
    </Location>
    Browsing Off
    Listen 127.0.0.1:631

    There are many more directives in the

    /etc/cups/cupsd.conf file that apply all print queues managed by the cupsd server.



  • /etc/cups/lpoptions—This file stores the default option settings that apply to all print jobs when you create a print queue as

    root . Note that users can specify other options when they print with the

    lp commands. Here is the

    /etc/cups/ lpoptions file with the default options for the

    Office-ES600 printer:

    Dest Office-ES600 page-bottom=36 cpi=12 lpi=7 scaling=100 page-right=36 page-left=36 wrap=true page-top=36



  • /etc/cups/ppd—This is a directory that contains the PostScript Printer Description (PPD) file for the Epson Stylus Color 600 printer in a file named

    Office-ES600 .ppd (the name I had assigned to that print queue). Each PPD file is a text file containing information about the printer capability (similar to the old

    /etc/ printcap file in intent, but PPD files have much more detailed information). Here are the first few lines from the PPD file

    /etc/cups/ppd/Office-ES600.ppd :

    *PPD-Adobe: "4.3"
    *%
    *% For information on using this, and to obtain the required backend
    *% script, consult http://www.linuxprinting.org/ppd-docl.
    *%
    *% PPD-O-MATIC generated this PPD file. It is for use with all programs
    *% and environments which use PPD files for dealing with printer capability
    *% information. The printer must be configured with a Foomatic backend
    *% filter script. This file and the backend filter script work together to
    *% support PPD-controlled printer driver option access with arbitrary free
    *% software printer drivers and printing spoolers.
    *%
    *% You may save this file as 'Epson-Stylus_Color_600-gimp-print.ppd'
    *%
    *%
    *FormatVersion: "4.3"
    *FileVersion: "1.1"
    *LanguageVersion: English
    *LanguageEncoding: ISOLatin1
    *PCFileName: "GIMP-PRI.PPD"
    *Manufacturer: "EPSON"
    *Product: "Stylus COLOR 600"
    *cupsVersion: 1.0
    *cupsManualCopies: True
    *cupsModelNumber: 2
    *cupsFilter: "application/vnd.cups-postscript 0 cupsomatic"
    *ModelName: "Epson Stylus Color 600, Foomatic + gimp-print"
    *NickName: "Epson Stylus Color 600, Foomatic + gimp-print"
    *ShortNickName: "Epson Stylus Color 600"
    *PSVersion: "(3010.000) 550"
    *PSVersion: "(3010.000) 651"
    *PSVersion: "(3010.000) 652"
    *PSVersion: "(3010.000) 653"
    *PSVersion: "(3010.000) 704"
    *PSVersion: "(3010.000) 705"
    *LanguageLevel: "3"
    *ColorDevice: True
    *DefaultColorSpace: RGB
    *FileSystem: False
    *Throughput: "1"
    *LandscapeOrientation: Plus90
    *VariablePaperSize: False
    *TTRasterizer: Type42
    *HWMargins: 0 0 0 0
    *VariablePaperSize: True
    *MaxMediaWidth: 100000
    .... many lines deleted ...

    That should give you an idea of the kind of information stored in PPD files. You don’t have to understand or prepare the PPD files manually. CUPS generates the PPD file automatically from descriptions in the Foomatic printer drivers that come with Red Hat Linux (described later in this chapter).



As this example shows, for each print queue it manages, CUPS needs a considerable amount of information stored in multiple configuration files. So far, I have shown you only the configuration files affected by the definition of a new print queue. It’s helpful to know the full extent of the configuration files, understand their purpose, and have a rough idea of what each of these files contain.








Secret


CUPS replies on a large number of configuration files to provide a comprehensive printing solution for Red Hat Linux. Although you do not have to manually edit these configuration files, be aware of what these files are and where they are stored. The key configuration files are located in the

/etc/cups directory and its subdirectories. Here is a brief summary of the configuration files:



  • /etc/cups/cupsd.conf—The CUPS HTTP server configuration file, used by cupsd, the CUPS scheduler and HPP server process. The directives in this file are similar to those used by the Apache httpd (Web server). This means that if you know how to read Apache httpd configuration file, you can also read and understand

    cupsd.conf . In particular,

    cupsd.conf defines access control for a printer in the same way that Apache httpd defines access control for a directory.



  • /etc/cups/printers.conf—Defines all available print queues. Information about each printer is in a <

    Printer

    PrinterName >

    ... <

    /Printer > block. A <

    DefaultPrinter > tag identifies the default printer.



  • /etc/cups/classes.conf—Contains definitions of all printer classes. A printer class is a collection of printers. Print jobs sent to a class are forwarded to the first available printer in the class.



  • /etc/cups/mime.types—Lists the supported MIME, types such as text/plain and application/postscript, and the rules for automatically detecting the format of a file. (MIME stands for Multipurpose Internet Mail Extensions, which began life as a way to send attachments in a single message file.) The cupsd server uses these rules to determine the type of a file.



  • /etc/cups/mime.convs—Contains the MIME conversion rules to convert a file into a format acceptable to a printer. The conversion is achieved by using filters. Each filter has a relative cost associated with it, and the filtering algorithm selects the set of filters that will convert the file to the needed format with the lowest total cost.



  • /etc/cups/ppd—Is a directory with the PostScript Printer Description (PPD) files for the printers being managed by CUPS. These PPD files describe the capabilities of all printers, not just PostScript printers. There is one PPD file for each printer. A PPD file for a non-PostScript printer identifies a filter with the

    cupsFilter attribute. CUPS uses that filter to convert a file into a firm suitable for sending to the printer. For example, the

    cupsFilter attribute for an Epson Stylus Color 600 printer identifies

    cupsomatic as the filter, like this:

    *cupsFilter:    "application/vnd.cups-postscript 0 cupsomatic"



  • The

    cupsomatic filter is located in the

    /usr/lib/cups/filter directory.



  • /etc/cups/client.conf—Specifies the default options for clients (in particular, the default server name and whether encryption is to be used or not). Note that a client is any machine that sends print jobs to another machine for final printing. This means that when your system prints to a local printer, it’s a client to the cupsd scheduler running on your system.














/ 341