From b106fb2da960cfed127366545945767bff315179 Mon Sep 17 00:00:00 2001 From: "Carl P. Corliss" Date: Fri, 11 Nov 2022 11:31:06 -0500 Subject: [PATCH 1/3] Update CUPs Documentation to use `cupsctl` Use `cupsctl` to make cupsd config changes, and `lpstat -W completed -o` in a cronjob to ensure configured pruning. --- .../README.md | 100 ++++-------------- 1 file changed, 23 insertions(+), 77 deletions(-) diff --git a/how-to-disable-cups-printer-job-history-on-macos/README.md b/how-to-disable-cups-printer-job-history-on-macos/README.md index 2f177a8..86b6a39 100644 --- a/how-to-disable-cups-printer-job-history-on-macos/README.md +++ b/how-to-disable-cups-printer-job-history-on-macos/README.md @@ -18,104 +18,50 @@ Listed: true ## Setup guide -### Step 1: clear job history - -> Heads-up: purges `/var/spool/cups`. +### Step 1: Reconfigure CUPS: ```shell -$ cancel -a -x +$ cupsctl MaxJobTime=5m PreserveJobFiles=no PreserveJobHistory=no ``` -### Step 2: create `/usr/local/sbin` directory +From [`cupsd.conf`](https://www.cups.org/doc/man-cupsd.conf.html) documentation: +
MaxJobs number
Specifies the maximum number of simultaneous jobs that are allowed. Set to "0" to allow an unlimited number of jobs; the default is "500".
MaxJobTime seconds
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).
PreserveJobFiles Yes | No | seconds
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).
PreserveJobHistory Yes | No | seconds
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".
+ +### 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 -sudo mkdir -p /usr/local/sbin -sudo chown ${USER}:admin /usr/local/sbin +$ lpstat -W completed -o ``` -### Step 3: create `cups.sh` script +### Step 3: Setup cronjob to clear out jobs + +> 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 -cat << "EOF" > /usr/local/sbin/cups.sh -#! /bin/sh - -set -e - -if grep -qe '^PreserveJobHistory Off$' /etc/cups/cupsd.conf; then - exit 0 +if ! crontab -l 2>/dev/null | grep -q CUPS-QUEUE-PURGE; then + 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") fi - -echo "PreserveJobHistory Off" | sudo tee -a /etc/cups/cupsd.conf - -sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist - -sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist -EOF ``` -### Step 4: make `cups.sh` executable - -```shell -chmod +x /usr/local/sbin/cups.sh -``` - -### Step 5: create `local.cups.plist` launch daemon - -```shell -cat << "EOF" | sudo tee /Library/LaunchDaemons/local.cups.plist - - - - - Label - local.cups - - ProgramArguments - - /usr/local/sbin/cups.sh - - - RunAtLoad - - - -EOF -``` - -### Step 6: reboot - 👍 --- ## Want things back the way they were before following this guide? No problem! -### Step 1: delete `PreserveJobHistory Off` line from `cupsd.conf` +### Step 1: Reset config parameters to defaults ```shell -sudo sed -i "" "/PreserveJobHistory Off/d" /etc/cups/cupsd.conf +$ cupsctl MaxJobTime= PreserveJobFiles= PreserveJobHistory= ``` -### Step 2: delete `cups.sh` script - -```shell -sudo rm /usr/local/sbin/cups.sh -``` - -### Step 3: delete `local.cups.plist` launch daemon - -```shell -sudo rm /Library/LaunchDaemons/local.cups.plist -``` - -### Step 4: reload CUPS - -```shell -sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist - -sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist -``` - -### Step 5: reboot - 👍 From 68baa6d9ff9361016c4b2cb4d6c4b22797da2367 Mon Sep 17 00:00:00 2001 From: Sun Knudsen Date: Tue, 15 Nov 2022 05:55:46 -0500 Subject: [PATCH 2/3] Cleaned up PR incorporating cupsctl and CUPS docs --- .../README.md | 92 ++++++++++++++----- 1 file changed, 68 insertions(+), 24 deletions(-) diff --git a/how-to-disable-cups-printer-job-history-on-macos/README.md b/how-to-disable-cups-printer-job-history-on-macos/README.md index 86b6a39..db043f2 100644 --- a/how-to-disable-cups-printer-job-history-on-macos/README.md +++ b/how-to-disable-cups-printer-job-history-on-macos/README.md @@ -2,7 +2,7 @@ Title: How to disable CUPS printer job history on macOS Description: Learn how to disable CUPS printer job history on macOS. Author: Sun Knudsen -Contributors: Sun Knudsen +Contributors: Sun Knudsen , Carl P. Corliss Reviewers: Publication date: 2022-10-29T13:05:18.112Z Listed: true @@ -18,50 +18,94 @@ Listed: true ## Setup guide -### Step 1: Reconfigure CUPS: +### Step 1: clear job history + +> Heads-up: purges `/var/spool/cups`. ```shell -$ cupsctl MaxJobTime=5m PreserveJobFiles=no PreserveJobHistory=no +$ cancel -a -x ``` -From [`cupsd.conf`](https://www.cups.org/doc/man-cupsd.conf.html) documentation: -
MaxJobs number
Specifies the maximum number of simultaneous jobs that are allowed. Set to "0" to allow an unlimited number of jobs; the default is "500".
MaxJobTime seconds
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).
PreserveJobFiles Yes | No | seconds
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).
PreserveJobHistory Yes | No | seconds
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".
- -### 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) +### Step 2: create `/usr/local/sbin` directory ```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 - -> 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: +### Step 3: create `cups.sh` script (see CUPS [docs](https://www.cups.org/doc/man-cupsd.conf.html)) ```shell -if ! crontab -l 2>/dev/null | grep -q CUPS-QUEUE-PURGE; then - 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") +cat << "EOF" > /usr/local/sbin/cups.sh +#! /bin/sh + +set -e + +if cupsctl | grep PreserveJobHistory=no > /dev/null 2>&1; then + exit 0 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 + + + + + Label + local.cups + + ProgramArguments + + /usr/local/sbin/cups.sh + + + RunAtLoad + + + +EOF +``` + +### Step 6: reboot + 👍 --- ## 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 -$ 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 + 👍 From 86d8954318b32b8565032a938f714f051a692c6c Mon Sep 17 00:00:00 2001 From: Sun Knudsen Date: Tue, 15 Nov 2022 13:09:16 -0500 Subject: [PATCH 3/3] Enabled grep quiet flag --- how-to-disable-cups-printer-job-history-on-macos/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/how-to-disable-cups-printer-job-history-on-macos/README.md b/how-to-disable-cups-printer-job-history-on-macos/README.md index db043f2..de6ce91 100644 --- a/how-to-disable-cups-printer-job-history-on-macos/README.md +++ b/how-to-disable-cups-printer-job-history-on-macos/README.md @@ -41,7 +41,7 @@ cat << "EOF" > /usr/local/sbin/cups.sh set -e -if cupsctl | grep PreserveJobHistory=no > /dev/null 2>&1; then +if cupsctl | grep --quiet PreserveJobHistory=no; then exit 0 fi