Cleaned up PR incorporating cupsctl and CUPS docs

This commit is contained in:
Sun Knudsen 2022-11-15 05:55:46 -05:00 committed by GitHub
parent b106fb2da9
commit 68baa6d9ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,7 @@
Title: How to disable CUPS printer job history on macOS Title: How to disable CUPS printer job history on macOS
Description: Learn how to disable CUPS printer job history on macOS. Description: Learn how to disable CUPS printer job history on macOS.
Author: Sun Knudsen <https://github.com/sunknudsen> Author: Sun Knudsen <https://github.com/sunknudsen>
Contributors: Sun Knudsen <https://github.com/sunknudsen> Contributors: Sun Knudsen <https://github.com/sunknudsen>, Carl P. Corliss <https://github.com/rabbitt>
Reviewers: Reviewers:
Publication date: 2022-10-29T13:05:18.112Z Publication date: 2022-10-29T13:05:18.112Z
Listed: true Listed: true
@ -18,50 +18,94 @@ Listed: true
## Setup guide ## Setup guide
### Step 1: Reconfigure CUPS: ### Step 1: clear job history
> Heads-up: purges `/var/spool/cups`.
```shell ```shell
$ cupsctl MaxJobTime=5m PreserveJobFiles=no PreserveJobHistory=no $ cancel -a -x
``` ```
From [`cupsd.conf`](https://www.cups.org/doc/man-cupsd.conf.html) documentation: ### Step 2: create `/usr/local/sbin` directory
<dl><dt><a name="MaxJobs"></a><b>MaxJobs </b><i>number</i></dt><dd style="margin-left: 5.0em">Specifies the maximum number of simultaneous jobs that are allowed. Set to "0" to allow an unlimited number of jobs; the default is "500".</dd><dt><a name="MaxJobTime"></a><b>MaxJobTime </b><i>seconds</i></dt><dd style="margin-left: 5.0em">Specifies the maximum time a job may take to print before it is canceled.
Set to "0" to disable cancellation of "stuck" jobs.
The default is "10800" (3 hours).</dd><dt><a name="PreserveJobFiles"></a><b>PreserveJobFiles</b> Yes | No | <i>seconds</i></dt><dd style="margin-left: 5.0em">Specifies whether job files (documents) are preserved after a job is printed.
If a numeric value is specified, job files are preserved for the indicated number of seconds after printing.
The default is "86400" (preserve 1 day).</dd><dt><a name="PreserveJobHistory"></a><b>PreserveJobHistory</b> Yes | No | <i>seconds</i></dt><dd style="margin-left: 5.0em">Specifies whether the job history is preserved after a job is printed.
If a numeric value is specified, the job history is preserved for the indicated number of seconds after printing.
If "Yes", the job history is preserved until the MaxJobs limit is reached.
The default is "Yes".</dd></dl>
### Step 2: clear job history
Clear out any completed jobs using the new settings from Step 1 (note: this does not affect any active jobs in the queue)
```shell ```shell
$ lpstat -W completed -o sudo mkdir -p /usr/local/sbin
sudo chown ${USER}:admin /usr/local/sbin
``` ```
### Step 3: Setup cronjob to clear out jobs ### Step 3: create `cups.sh` script (see CUPS [docs](https://www.cups.org/doc/man-cupsd.conf.html))
> Note: Jobs *should* automatically be purged upon completion if you're using the settings above, but *may* persist in some specific cases (e.g., if cups is restarted in the middle of a job, [see this](https://access.redhat.com/solutions/5914031)). This cron job will ensure that any jobs that persist are cleaned out using the `PreserveJobFiles` and `PreserveJobHistory` settings you defined in Step 1:
```shell ```shell
if ! crontab -l 2>/dev/null | grep -q CUPS-QUEUE-PURGE; then cat << "EOF" > /usr/local/sbin/cups.sh
crontab <(crontab -l 2>/dev/null; echo -en "\n# CUPS-QUEUE-PURGE: ensure that print jobs are cleaned out after they're expired\n* * * * * /usr/bin/lpstat -W completed -o") #! /bin/sh
set -e
if cupsctl | grep PreserveJobHistory=no > /dev/null 2>&1; then
exit 0
fi fi
cupsctl MaxJobTime=5m PreserveJobFiles=no PreserveJobHistory=no
EOF
``` ```
### Step 4: make `cups.sh` executable
```shell
chmod +x /usr/local/sbin/cups.sh
```
### Step 5: create `local.cups.plist` launch daemon
> Heads-up: used to make sure user-defined config persists macOS updates.
```shell
cat << "EOF" | sudo tee /Library/LaunchDaemons/local.cups.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.cups</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/cups.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
```
### Step 6: reboot
👍 👍
--- ---
## Want things back the way they were before following this guide? No problem! ## Want things back the way they were before following this guide? No problem!
### Step 1: Reset config parameters to defaults ### Step 1: delete `cups.sh` script
```shell ```shell
$ cupsctl MaxJobTime= PreserveJobFiles= PreserveJobHistory= sudo rm /usr/local/sbin/cups.sh
``` ```
### Step 2: delete `local.cups.plist` launch daemon
```shell
sudo rm /Library/LaunchDaemons/local.cups.plist
```
### Step 3: revert user-defined config to CUPS defaults
```shell
cupsctl MaxJobTime= PreserveJobFiles= PreserveJobHistory=
```
### Step 4: reboot
👍 👍