Skip to content

Instantly share code, notes, and snippets.

@towo
Last active February 11, 2025 08:58
Show Gist options
  • Save towo/fab8180e0d2af848946864cb36187f3f to your computer and use it in GitHub Desktop.
Save towo/fab8180e0d2af848946864cb36187f3f to your computer and use it in GitHub Desktop.
Brother QL web podman autostart when plugging in with USB
SUBSYSTEM=="usb", ATTRS{idVendor}=="$VENDORID", ATTRS{idProduct}=="$PRODUCTID", TAG+="systemd", ENV{SYSTEMD_USER_WANTS}+="brother_ql_web.service", ENV{SYSTEMD_ALIAS}+="/sys/subsystem/lp/devices/$attr{product}/$attr{serial}", SYMLINK+="$attr{product}-$attr{serial}"

Autostart brother_ql_web

This is a simple setup for automatically starting brother_ql_web as soon as you plug it into your computer, and have it automatically stop when the printer is disconnected or enters suspend.

This procedure is based on using rootless podman with a systemd user instance, which makes the whole process pretty tight, all things considered.

Things to do

  1. Make sure you've got some fonts in ${XDG_DATA_HOME}/fonts.
  2. Ensure you're in the right group to actually access your USB printer (obviously)
  3. Get your idVendor (should be 04f9) and idProduct (e.g. 2028 for a QL-570) by using udevadm info --attribute-walk --path=$(udevadm info --query=path --name=/dev/usb/lp0)
  4. Replace the appropriate entries ($VENDORID, $PRODUCTID) in 70-brother-printer.rules.
  5. Put the configuration into /etc/udev/rules.d, reload with udevadm control --reload.
  6. Power cycle the printer.
  7. Ensure everything worked by doing systemctl list-units | grep sys--subsystem-lp-devices and checking for your printer serial in there.
  8. Replace $TYPE (syntax) and $SERIAL in brother_ql_web.container and put it into ${XDG_CONFIG_HOME}/containers/systemd (i.e. usually ~/.config/containers/systemd)
  9. Reload the container unit with systemctl --user daemon-reload.
  10. Power cycle the printer.
  11. You should see the printer web service container starting in the journal, check the output; when finished, it'll be available at http://127.0.0.1:8013/
[Unit]
Description=Brother label printer web service
BindsTo=sys-subsystem-lp-devices-$TYPE-$SERIAL.device
[Container]
Volume=${XDG_DATA_HOME}/fonts:/fonts
PublishPort=127.0.0.1:8013:8013
Image=docker.io/pklaus/brother_ql_web:latest
Exec=./brother_ql_web.py --model $TYPE --font-folder /fonts file:///dev/$TYPE-$SERIAL
GroupAdd=keep-groups
AddDevice=/dev/$TYPE-$SERIAL
[Install]
WantedBy=graphical-session.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment