I recently spent a day onsite during half term looking at a set of iMacs that were intermittently pausing their print queues. I used a few different terminal commands to work around the issue so I thought I’d share the findings.
The setup was a classroom of Macs with a single HP A3 colour laser printer. Printing was through a Windows print server using Equitrak print management software.
The Symptom
Intermittently the printer on one of the Macs (it was random as to which one was affected) was paused. Attempting to start the printer was unsuccessful.
I enabled the cups interface in the Terminal on one of the affected Macs with:
cupsctl WebInterface=yes
I then logged on to the web interface: http://127.0.0.1:631 and looked at the printer. The queue had a load of stuck jobs from different users that had logged on.
The workaround
In this case, it had to be a workaround. There is clearly an underlying problem causing the print queue to pause but being half term at this particular site it was a ghost town, and no-one had access to the print server to investigate further.
The paused jobs in the CUPS web interface were not much help, other than to state that they were stuck.
So to work around this problem we wanted a way to clear out any stuck jobs and to restart the queue when a new user logs in. This was achieved with the following script:
#!/bin/sh
cancel -a - # Clears the stuck jobs in all queues
cupsenable PRINTER # Restarts the print queue
exit 0
You would need to replace “PRINTER” with the actual name of the print queue. You can get this by using:
lpstat -p
Given more time it would be worth expanding this script to check if the printer is running and only use cupsenable if needed. It could also specify which queues to clear. But for the requirement I had, this was sufficient.
Next we needed to get the script triggered. There are a bunch of ways to do this (see this podcast if you are wondering about the other options). In this case, I am using a LaunchAgent. This is because:
- I want the script to run each time a user logs in
- There was already a login and logout hook that I didn’t want to interfere with
The LaunchAgent was placed in /Library/LaunchAgents and looks like this:
Label
uk.co.amsys.clearqueue
ProgramArguments
/Library/Amsys/clear_queue.sh
RunAtLoad
With LaunchAgents, it’s important to make sure the permissions and ownership are set correctly. It needs to be owned by root, and the group set to wheel. The permissions also must match the other LaunchAgents that are already in there (i.e. -rw-r—r—). If the permissions are set too restrictively or too promiscuously, they won’t be used.
That’s it; each time a user logs in the queue is cleared and the printer resumed.
Extra Note: Before choosing “cancel -a -” I was testing “lprm -” which appeared to have the same effect. This was failing to run for non-admin users so I switched to the cancel command. Just in case anyone wonders!
Disclaimer:
While the author has taken care to provide our readers with accurate information, please use your discretion before acting upon information based on the blog post. Amsys will not compensate you in any way whatsoever if you ever happen to suffer a loss/inconvenience/damage because of/while making use of information in this blog.