xref: /plan9/sys/doc/lp.ms (revision 2cca75a1b2b8c6083390679d69d5c50cf66d9a01)
1.HTML "A Guide to the Lp Printer Spooler
2.TL
3A Guide to the Lp
4Printer Spooler
5.AU
6Paul Glick
7pg@plan9.bell-labs.com
8.AB
9.PP
10.I Lp
11is a collection of programs used to provide an easy-to-use
12interface for printing a variety of document types on a variety
13of printers.
14.I Lp
15is the glue that connects various document language
16translators and printer communication programs together so that
17the users may have a consistent view of printers.
18Most of the glue
19is shell script, which can be easily modified.
20The user need not
21specify options to get sensible output in most cases.
22.I Lp
23is described here
24so that others may make additions and changes.
25.AE
26\" .2C
27.NH
28Introduction
29.PP
30.I Lp
31is used to format and print data on a variety of output devices.
32The need for
33.I lp
34was rooted in the inability of other printer spoolers to do simple
35tasks without a great deal of user specification of options.
36At the time
37.I lp
38was written, there were several printer
39languages, such as ImPress and PostScript, and
40an internally developed printer that would accept
41.I troff
42output.
43Now, all our printers take PostScript,
44but printers that use HPCL and HPGL abound and
45support for those printers may be added easily.
46A great deal of what underlies
47.I lp
48is taken from BSD's
49.I lpr
50and System V's
51.I lp .
52The important features of this system are that most of the programs
53are easily modified shell scripts and the user need not
54learn to use the large amount of underlying software developed by others.
55.I Lp
56runs under Plan 9 and several flavors of
57UNIX.
58This document deals with
59.I lp
60as it relates to Plan 9.
61.I Lp
62was developed using both Datakit and Ethernet to transport data between machines.
63Now only the Ethernet transport mechanism remains.
64.PP
65Text, graphics, and formatted text files are appropriately processed and
66placed into a spool directory from which they are taken to be printed by a daemon process.
67Additional functions include checking the status of a printer queue
68and removing jobs from the printer queue.
69.PP
70All the shell scripts (see
71.I rc (1))
72associated with
73.I lp
74reside in the spool directory
75.CW /sys/lib/lp
76except for the
77.I lp
78command itself, which resides in
79.CW /rc/bin .
80Commands related to
81.I lp
82that are not shell scripts can most often be found
83in
84.CW /$cputype/bin/aux .
85The directory where all the
86.I lp
87scripts  reside is defined within
88.I lp
89by the shell variable
90.CW LPLIB .
91In the remainder of this document, file names will be specified
92with this shell variable as their root.
93.NH
94Usage
95.PP
96.I Lp
97requires an output device to be specified
98before it will process input.
99This can be done in any of three ways described here.
100.IP 1)
101The file
102.CW $LPLIB/defdevice
103may contain the name of a default output device.
104This may not be practical for environments where
105there are many printers.
106.IP 2)
107The user's environment variable
108.CW LPDEST
109may be set to the name of the device to be used.
110This is often a more practical solution when there are several printers
111available.
112This overrides a
113.CW defdevice
114specification.
115.IP 3)
116The
117.CW -d
118.I printer
119option to the
120.I lp
121command specifies
122.I printer
123as the device to which output should be directed, overriding the
124previous two specifications.
125.PP
126.ti 0
127If
128.I printer
129is
130.CW ? ,
131a list of printers and other information in the
132.CW devices
133file is printed, as shown in Figure 1.
134Quote the question mark to prevent it from being
135interpreted by the shell language as a metacharacter.
136\" .1C
137.KF
138.P1
139% lp -d'?'
140device   location  host             class
141fn       2C-501    helix            post/2+600dpi+duplex
142pcclone  -         -                post+nohead
143peacock  2C-501    cetus            post/2+300dpi+nohead+color
144ps83     st8_fl3   rice             post+300dpi+reverse
145psu      2C-501    cetus            post/2+1200dpi
146     .
147     .
148     .
149%
150.P2
151.ce
152.I "Figure 1.  Sample listing of installed printers"
153.KE
154.PP
155Normally,
156.I lp
157uses the
158.CW file
159command to figure out what type of input it is receiving.
160This is done within the
161.CW generic
162process which is discussed later in this paper in the
163.B "Process directory"
164section.
165To select a specific input processor the
166\f(CW-p\fP\fIprocess\fP
167option is used where
168.I process
169is one of the shell scripts in the
170.CW process
171directory.
172.LP
173Troff
174output can be printed, in this case, on printer
175.I fn
176with
177.P1
178% troff -ms lp.ms | lp -dfn
179.P2
180.LP
181A file can be converted to PostScript using the pseudo-printer
182.CW stdout :
183.P1
184% troff -ms lp.ms | lp -dstdout > lp.ps
185.P2
186LaTeX (and analogously TeX)
187documents are printed in two steps:
188.P1
189% latex lp.tex
190     .
191     .
192% lp lp.dvi
193     .
194     .
195%
196.P2
197LaTeX
198produces a `.dvi' file and
199does not permit the use of a pipe
200connection to the standard input of
201.I lp .
202To look at the status and queue of a device, use
203.CW -q :
204.P1
205% lp -dpsu -q
206daemon status:
207:  67.17% sent
208printer status:
209%%[ status: busy; source: lpd ]%%
210
211queue on cetus:
212job		user	try	size
213rice29436.1	pg	0	17454
214slocum17565.1	ches	1	49995
215%
216.P2
217This command can print the status and queue of the local
218and remote hosts.
219Administrators should be advised that working in an environment where the
220.I lp
221spool directory is shared among the local and remote hosts,
222no spooling should be done on the local hosts.
223The format of the status and queue printout is up to the administrator.
224The job started above can be killed with
225.CW -k :
226.P1
227$ lp -dpsu -k rice29436.1
228rice29436.1 removed from psu queue on cetus
229.P2
230.NH
231Options
232.PP
233There are options available to modify the way in which a job is handled.
234It is the job of the
235.I lp
236programs to convert the option settings so they may be used by each of the
237different translation and interface programs.
238Not all options are applicable to all printer environments.
239Table 1 lists the standard
240.I lp
241options, the shell variable settings, and description of the options.
242\" .1C
243.KF
244.sp
245.in 0
246.TS
247center;
248c | c s s | c
249c | c c c | c
250lfCWp-2 | lfCWp-2 cfCWp-2 cfCWp-2 | lp-2w(3i).
251=
252option	shell variable	action
253\^	name	default	set	\^
254_
255-D	DEBUG	N	1	turn on debugging mode.
256_
257-H	NOHEADER	N	1	suppress header page.
258_
259-L	LAND	N	1	make long page dimension horizontal.
260_
261-M \fImach\fP	LPMACHID	N	\fImach\fP	set the source machine name.
262_
263-Q	QONLY	N	1	do not execute daemon; for debugging.
264_
265-c \fIn\fP	COPIES	N	\fIn\fP	number of copies to be printed.
266_
267-d \fIprinter\fP	LPDEST	U	\fIprinter\fP	set job destination; override other settings.
268_
269-f \fIfont.pt\fP	FONT	N	\fIfont\fP	set font style and point size for printing.
270	POINT	N	\fIpt\fP
271_
272-i \fIn\fP	IBIN	N	\fIn\fP	T{
273select input paper tray options.
274The argument given is dependent on the printer type.
275A number can be given to select a particular tray and/or
276.CW simplex
277or
278.CW duplex
279may be used to get single or double sided output, where
280applicable.
281Multiple options should be separated by commas.
282T}
283_
284-k	KILLFLAG	0	1	T{
285take non-option arguments as job numbers to be removed from queue.
286T}
287_
288-l \fIn\fP	LINES	N	\fIn\fP	T{
289for printed data, the number of lines per logical page.
290T}
291_
292-m \fIf\fP	MAG	N	\fIf\fP	T{
293magnify the image by a factor \fIf\fP.
294The factor should be a positive real number.
295T}
296_
297-n \fIn\fP	NPAG	N	\fIn\fP	T{
298put \fIn\fP logical pages on a single physical page.
299A simple algorithm is used to pack the pages.
300T}
301_
302-o \fIlist\fP	OLIST	N	\fIlist\fP	T{
303print only those pages specified in the list.
304The list may be a sequence of numbers or ranges separated by commas.
305A range is a pair of numbers separated by a hyphen.
306T}
307_
308-p \fIproc\fP	LPPROC	L	\fIproc\fP	T{
309use the preprocessor \fIproc\fP instead of the preprocessor given
310in the
311.CW devices
312file for this printer.
313T}
314_
315-q	LPQ	N	1	T{
316print the status and queue.
317T}
318_
319-r	REVERSE	L	1	T{
320this toggles the
321.CW REVERSE
322flag, changing whether or not page reversal should occur in preprocessing.
323Page reversal is needed if a printer delivers pages face up.
324The keyword
325.CW reverse
326can be placed in the
327.I lpclass
328field of the
329.CW devices
330file.
331If a document has already been processed this flag has no effect.
332T}
333_
334-u \fIuser\fP	LPUSERID	U	\fIuser\fP	T{
335change the user id that appears on the cover page.
336T}
337_
338-x \fIoffset\fP	XOFF	N	\fIoffset\fP	T{
339move the image \fIoffset\fP inches to the right.
340A negative \fIoffset\fP will move the image to the left.
341The \fIoffset\fP may be any reasonable real number.
342T}
343_
344-y \fIoffset\fP	YOFF	N	\fIoffset\fP	T{
345same as for
346.CW -x
347except a positive offset will move the image down.
348T}
349_
350.T&
351l l cp-2 lp-2 s
352l l cfCWp-2 lp-2 s.
353.vs -2p
354
355		default	setting definition
356		N	set to the null string (`') initially in \fIlp\fP.
357		L	set from printer entry in \f(CW\\s-\\n(XPdevices\\s+\\n(XP\fP file.
358		U	set from the user's environment.
359.vs +2p
360.TE
361.sp
362.ce
363.I "Table 1. Lp Option List"
364.sp
365.ll \\n(LLu
366.KE
367\" .2C
368.NH
369Devices file
370.PP
371The
372.CW devices
373file is found in the spool directory.
374Each line in the file is composed of 12 fields, separated
375by tabs or spaces, that describe the attributes
376of the printer and how it should be serviced.
377Within the
378.CW lp
379command, a shell variable is set for each attribute;
380the following list describes them:
381.IP "\f(CW\s-\n(XPLPDEST\s+\n(XP\fP " 12
382is the name of the device as given to
383.I lp
384with the
385.CW -d
386option
387or as specified by the shell environment variable
388.CW LPDEST
389or as specified by
390the file
391.CW $LPLIB/defdevice .
392This name is used in creating directories and log files that are associated with
393the printers operation.
394.IP "\f(CW\s-\n(XPLOC\s+\n(XP\fP "
395just describes where the printer is physically located.
396.IP "\f(CW\s-\n(XPDEST_HOST\s+\n(XP\fP "
397is the host from which the files are printed.
398Files may be spooled on other machines before being transferred to the
399destination host.
400.IP "\f(CW\s-\n(XPOUT_DEV\s+\n(XP\fP "
401is the physical device name or network address needed by the printer daemon
402to connect to the printer.
403This field depends on the requirements of the daemon and may contain a `\(en'
404if not required.
405.IP "\f(CW\s-\n(XPSPEED\s+\n(XP\fP "
406is the baud rate setting for the port.
407This field depends on the requirements of the daemon and may contain a `\(en'
408if not required.
409.IP "\f(CW\s-\n(XPLPCLASS\s+\n(XP\fP "
410is used to encode minor printer differences.
411The keyword
412.CW reverse
413is used by some of the preprocessors
414to reverse the order the pages are printed to accommodate different output
415trays (either face up or face down).
416The keyword
417.CW nohead
418is used to suppress the header page.
419This is used for special and color printers.
420The keyword
421.CW duplex
422is used to coax double sided output from duplex printers.
423.IP "\f(CW\s-\n(XPLPPROC\s+\n(XP\fP "
424is the command from the
425.CW LPLIB/process
426directory to be used to convert input to a format
427that will be accepted by the device.
428The preprocessor is invoked by the spooler.
429.IP "\f(CW\s-\n(XPSPOOLER\s+\n(XP\fP "
430is the command from the
431.CW LPLIB/spooler
432directory which will select files using the
433.CW SCHED
434command and invoke the
435.CW LPPROC
436command, putting its output
437into the remote spool directory.
438The output is sent directly to the spool directory on the
439destination machine to avoid conflicts when client and
440server machines share spool directories.
441.IP "\f(CW\s-\n(XPSTAT\s+\n(XP\fP "
442is the command from the
443.CW LPLIB/stat
444directory that prints the status of the device and the list of jobs
445waiting on the queue for the device.
446The status information depends on what is available from the printer
447and interface software.
448The queue information should be changed to show information
449useful in tracking down problems.
450The
451.CW SCHED
452command is used to show the jobs in the order
453in which they will be printed.
454.IP "\f(CW\s-\n(XPKILL\s+\n(XP\fP "
455is the command from the
456.CW LPLIB/kill
457that removes jobs from the queue.
458The jobs to be removed are given as arguments to the
459.I lp
460command.
461When possible, it should also abort the currently running job
462if it has to be killed.
463.IP "\f(CW\s-\n(XPDAEMON\s+\n(XP\fP "
464is the command from the
465.CW LPLIB/daemon
466that is meant to run asynchronously to remove
467jobs from the queue.
468Jobs may either be passed on to another host or sent to the
469printing device.
470.I Lp
471always tries to start a daemon process when one is specified.
472.IP "\f(CW\s-\n(XPSCHED\s+\n(XP\fP "
473is the command from the
474.CW LPLIB/sched
475that is used to present the job names to the
476daemon and stat programs
477in some order, e.g., first-in-first-out, smallest first.
478.NH
479Support programs
480.PP
481The following sections describe the basic functions of the programs
482that are found in the subdirectories of
483.CW $LPLIB .
484The programs in a specific directory vary with the
485type of output device or networks that have to be used.
486.NH 2
487Process directory
488.PP
489The
490.CW generic
491preprocessor
492is the default preprocessor for most printers.
493It uses the
494.I file (1)
495command to determine the format of the input file.
496The appropriate preprocessor is then selected to transform the
497file to a format suitable for the printer.
498.PP
499Here is a list of some of the preprocessors and
500a description of their function.
501A complete list of preprocessors and their descriptions can be found in the manual page
502.I lp (8).
503.sp
504.IP \f(CWdvipost\fP 14
505Converts TeX or LaTeX output (\f(CW.dvi\fP files) to PostScript
506.IP \f(CWppost\fP
507Converts UTF text to PostScript.
508The default font is Courier with Lucida fonts filling in
509the remainder of the (available) Unicode character space.
510.IP \f(CWtr2post\fP
511Converts (device independent) troff output for the device type
512.CW utf .
513See
514.CW /sys/lib/troff/font/devutf
515directory for troff font width table descriptions.
516See also the
517.CW /sys/lib/postscript/troff
518directory for mappings of
519troff
520.CW UTF
521character space to PostScript font space.
522.IP \f(CWp9bitpost\fP
523Converts Plan 9 bitmaps (see
524.I bitfile (9.6))
525to PostScript.
526.IP \f(CWg3post\fP
527Converts fax (CCITT-G31 format) to PostScript.
528.IP \f(CWhpost\fP
529Does header page processing and page reversal processing, if
530necessary.
531Page reversal is done here so the header page always comes
532out at the beginning of the job.
533Header page processing is very location-dependent.
534.NH 2
535Spool directory
536.PP
537The
538.CW generic
539spooler is responsible for executing the preprocessor
540and directing its output to a file in the printer's queue.
541An additional file is created containing information such as the system name,
542user id, job number, and number of times this job was attempted.
543.PP
544Certain printer handling programs do not require separate
545preprocessing and spooling.
546For such circumstances a
547.CW nospool
548spooler is available that just executes the preprocessing program.
549The processing and spooling functions are assumed by this program and the output is sent to
550.CW OUT_DEV
551or standard output if
552.CW OUT_DEV
553is '-'.
554.PP
555The
556.CW pcclone
557spooler is used to send print jobs directly to a printer connected
558to a 386 compatible printer port (See
559.I lpt (3)).
560.NH 2
561Stat directory
562.PP
563The function of the shell scripts in the
564.CW stat
565directory is to present status information about the
566printer and its queue.
567When necessary, the
568.CW stat
569scripts may be designed
570to return information about the local queue as well as the remote queue.
571This is not done on Plan 9 because many systems share the same queue directory.
572The scheduler is used to print the queue in the order in which the jobs
573will be executed.
574.NH 2
575Kill directory
576.PP
577The
578.CW kill
579scripts receive command line arguments passed to them by
580.I lp
581and remove the job and id files which match the arguments
582for the particular queue.
583When a job is killed, the generic kill procedure:
584.IP 1)
585kills the daemon for this queue if the job being killed
586is first in the queue,
587.IP 2)
588removes the files associated with the job from the queue,
589.IP 3)
590attempts to restart the daemon.
591.NH 2
592Daemon directory
593.PP
594The
595.CW daemon
596shell scripts are the last to be invoked by
597.I lp
598if the
599.CW -Q
600option has not been given.
601The daemon process is executed asynchronously
602with its standard output and standard error appended to
603the printer log file.
604The log file is described in a subsequent section.
605Because the daemon runs asynchronously, it must
606catch signals that could cause it to terminate abnormally.
607The daemon first checks to see that it is the only one running
608by using the
609.CW LOCK
610program found in the
611.CW /$cputype/bin/aux
612directory.
613The
614.CW LOCK
615command creates a
616.CW LOCK
617file in the printer's queue directory.
618The daemon then executes the scheduler to obtain the name of the
619next job on the queue.
620.PP
621The processing of jobs may entail transfer to another host
622or transmission to a printer.
623The details of this are specific to the individual daemons.
624If a job is processed without error, it is removed from the queue.
625If a job does not succeed, the associated files may be
626moved to a printer specific directory in
627.CW $LPLIB/prob .
628In either case, the daemon can make an entry in the printer's
629log file.
630Before exiting, the daemon should clean up lock files by calling
631.CW UNLOCK .
632.PP
633Several non-standard daemon programs have been designed
634to suit various requirements and whims.
635One such program announces job completion and empty paper trays
636by causing icons to appear in peoples'
637.CW seemail
638window.
639Another, using a voice synthesizer, makes verbal announcements.
640Other daemons may be designed to taste.
641.NH 2
642Sched directory
643.PP
644The scheduler must decide which job files should be executed and
645in what order.
646The most commonly used scheduler program is
647.CW FIFO ,
648which looks like this:
649.P1
650ls -tr $* | sed -n -e 's/.*  *//' \e
651  -e '/^[0-9][0-9]*\.[1-9][0-9]*$/p'
652.P2
653This lists all the job files in this printer's queue in modification
654time order.
655Jobs entering the queue have a dot (.) prefixed to their name
656to keep the scheduler from selecting them before they are complete.
657.NH
658Where Things Go Wrong
659.PP
660There are four directories where
661.I lp
662writes files.
663On the Plan 9 release these directories may be found
664in a directory on a scratch filesystem that is not
665backed-up.
666This directory is
667.CW /n/emelieother/lp .
668It is built on top of a file system
669.CW other
670that is mounted on the file server
671.CW emelie .
672The four directories in
673this scratch directory
674are
675.CW log ,
676.CW prob ,
677.CW queue ,
678and
679.CW tmp .
680.I Lp
681binds (see
682.I bind (1))
683the first three into the directory
684.CW /sys/lib/lp
685for its processes and their children.
686The
687.CW tmp
688directory is bound to the
689.CW /tmp
690directory so that the lp daemons, which run as user `none',
691may write into this directory.
692.PP
693On any new installation, it is important that these directories
694be set up and that the
695.I /rc/bin/lp
696command be editted to reflect the change.
697If you do not have a scratch filesystem for these directories,
698create the four directories
699.CW log ,
700.CW prob ,
701.CW queue ,
702and
703.CW tmp
704in
705.CW $LPLIB
706.CW (/sys/lib/lp)
707so that they are writable by anyone.
708.NH 2
709Log directory
710.PP
711The log files for a particular
712.I printer
713appear in a subdirectory of the spool directory
714\f(CWlog\fP/\fIprinter\fP.
715There are currently two types of log files.
716One is for the daemon to log errors and successful completions
717of jobs.
718These are named
719.I printer.day
720where
721.I day
722is the three letter abbreviation for the day of the week.
723These are overwritten once a week to avoid the need for regular
724cleanup.
725The other type of log file contains the status of the printer and
726is written by the program that communicates with the printer itself.
727These are named
728\fIprinter\fP.\f(CWst\fP.
729These are overwritten with each new job and are saved in the
730.CW $LPLIB/prob
731directory along with the job under circumstances described below.
732When a printer does not appear to be functioning these files are the
733place to look first.
734.NH 2
735Prob directory
736.PP
737When a job fails to produce output,
738the log files should be checked for any obvious problems.
739If none can be found, a directory with full read and write permissions
740should be created with the name of the printer in the
741.CW $LPLIB/prob
742directory.
743Subsequent failure of a job will cause the daemon to leave a
744copy of the job and the printer communication log in
745\f(CW$LPLIB/prob/\fP\fIprinter\fP
746directory.
747It is common for a printer to enter states from which
748it cannot be rescued except by manually cycling the power on the printer.
749After this is done the print daemon should recover by itself
750(give it a minute).
751If it does not recover, remove the
752.CW LOCK
753file from the printer's spool directory to kill the daemon.
754The daemon will have to be restarted by sending another job
755to the printer.
756For PostScript printers just use:
757.P1
758echo '%!PS' | lp
759.P2
760.NH 2
761Repairing Stuck Daemons
762.PP
763There are conditions that occur which are not handled
764by the daemons.
765One such problem can only be described as the printer entering a
766comatose state.
767The printer does not respond to any messages sent to it.
768The daemon should recover from the reset and an error message
769will appear in the log files.
770If all else fails, one can kill the first job in the queue
771or remove the
772.CW LOCK
773file from the queue directory.
774This will kill the daemon, which will have to be restarted.
775.NH
776Interprocessor Communication
777.PP
778A Plan 9 CPU server can be set up as a printer's spooling host.
779That is, the machine where jobs are spooled and from which those jobs
780are sent directly to the printer.
781To do this, the CPU must listen on TCP port 515 which is the well known
782port for the BSD line printer daemon.
783The file
784.CW /rc/bin/service/tcp515
785is executed when a call comes in on that port.
786The Plan 9
787.CW lpdaemon
788will accept jobs sent from BSD LPR/LPD systems.
789The
790.CW /$cputype/bin/aux/lpdaemon
791command is executed from the service call and it accepts print jobs, requests for status,
792and requests to kill jobs.
793The command
794.CW /$cputype/bin/aux/lpsend
795is used to send jobs
796to other Plan 9 machines and is usually called from
797within a spooler or daemon script.
798The command
799.CW /$cputype/bin/aux/lpdsend
800is used to send jobs
801to machines and printers that use the BSD LPR/LPD protocol and is also usually called from
802within a spooler or daemon script.
803.NH
804Acknowledgements
805.PP
806Special thanks to Rich Drechsler for supplying and maintaining most of
807the PostScript translation and interface programs,
808without which
809.I lp
810would be an empty shell.
811Tomas Rokicki provided the
812TeX
813to PostScript
814translation program.
815.NH
816References
817.LP
818[Camp86] Ralph Campbell,
819``4.3BSD Line Printer Spooler Manual'', UNIX System Manager's Manual,
820May, 1986, Berkeley, CA
821.br
822[RFC1179] Request for Comments: 1179, Line Printer Daemon Protocol, Aug 1990
823.br
824[Sys5] System V manual, date unknown
825