KASM-5766 Add the ability to wait on the printer service

Some use-cases require the printer to be ready before an app can be
loaded. These updates allow the admin to be more agressive in the cups
startup and to use /usr/bin/printer_ready to block on the printer in
both the vnc_startup and custom_startup scripts
This commit is contained in:
Justin Travis 2024-03-15 15:50:05 -04:00
parent e458919227
commit 2870104a39
No known key found for this signature in database
3 changed files with 31 additions and 1 deletions

View File

@ -344,6 +344,16 @@ function start_printer (){
fi
}
function wait_on_printer (){
# Wait for cups and the printer device to be created
if [[ ${KASM_SVC_PRINTER:-1} == 1 && ${KASM_PRINTER_WAIT:-0} == 1 ]]; then
log 'Waiting on printer service to be ready'
/usr/bin/printer_ready
log 'Printer is ready'
fi
}
function custom_startup (){
custom_startup_script=/dockerstartup/custom_startup.sh
if [ -f "$custom_startup_script" ]; then
@ -504,6 +514,7 @@ chmod 600 $PASSWD_PATH
# start processes
wait_on_printer
start_kasmvnc
start_window_manager
start_audio_out_websocket

View File

@ -32,3 +32,22 @@ ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g')
mkdir -p $STARTUPDIR/printer
wget -qO- https://kasmweb-build-artifacts.s3.amazonaws.com/kasm_printer_service/${COMMIT_ID}/kasm_printer_service_${ARCH}_${BRANCH}.${COMMIT_ID_SHORT}.tar.gz | tar -xvz -C $STARTUPDIR/printer/
echo "${BRANCH}:${COMMIT_ID}" > $STARTUPDIR/printer/kasm_printer.version
cat >/usr/bin/printer_ready <<EOL
#!/usr/bin/env bash
set -x
if [[ ${KASM_SVC_PRINTER:-1} == 1 ]]; then
PRINTER_NAME=${KASM_PRINTER_NAME:-Kasm-Printer}
until [[ "$(lpstat -r)" == "scheduler is running" ]]; do sleep 1; done
echo "Scheduler is running"
until lpstat -p "$PRINTER_NAME" | grep -q "is idle"; do
sleep 1
done
echo "Printer $PRINTER_NAME is idle."
else
echo "Printing service is not enabled"
fi
EOL
chmod +x /usr/bin/printer_ready

View File

@ -7,7 +7,7 @@ set -ex
# HACK: Some versions of cupsd cannot handle unlimited file descriptor limit
# that docker sets..
ulimit -n 1024 &&/usr/sbin/cupsd -f &
until [[ "$(lpstat -r)" == "scheduler is running" ]]; do sleep 15; done
until [[ "$(lpstat -r)" == "scheduler is running" ]]; do sleep ${KASM_CUPS_SLEEP:-15}; done
echo "Creating a virtual printer: $PRINTER_NAME"
lpadmin -p $PRINTER_NAME -E -v cups-pdf:/ -P /etc/cups/ppd/kasm.ppd