From 7b25692d03a1758812b7a23dac8f0fff8c9af047 Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Thu, 20 Mar 2025 01:05:53 +0530 Subject: [PATCH 1/7] Introducing immutability to IPP-USB OCI image --- rock/rockcraft.yaml | 194 ++++++++++++++++++++++++++++++++---- rock/scripts/run-avahi.sh | 18 ++++ rock/scripts/run-dbus.sh | 45 --------- rock/scripts/run-ipp-usb.sh | 15 ++- 4 files changed, 208 insertions(+), 64 deletions(-) create mode 100644 rock/scripts/run-avahi.sh delete mode 100644 rock/scripts/run-dbus.sh diff --git a/rock/rockcraft.yaml b/rock/rockcraft.yaml index 01be1f2..0ce1978 100644 --- a/rock/rockcraft.yaml +++ b/rock/rockcraft.yaml @@ -9,6 +9,7 @@ description: | license: Apache-2.0 adopt-info: ipp-usb +run-user: _daemon_ platforms: amd64: @@ -16,8 +17,8 @@ platforms: armhf: services: - dbus: - command: /scripts/run-dbus.sh + avahi-daemon: + command: /scripts/run-avahi.sh override: replace on-failure: restart startup: enabled @@ -27,7 +28,7 @@ services: startup: enabled override: replace on-failure: restart - after: [dbus] + after: [avahi-daemon] parts: goipp: @@ -114,35 +115,192 @@ parts: make -j$CRAFT_PARALLEL_BUILD_COUNT make install DESTDIR=$CRAFT_PART_INSTALL - avahi-daemon: - plugin: nil - build-packages: - - avahi-daemon - overlay-packages: + avahi: + plugin: autotools + source: https://github.com/avahi/avahi.git + source-type: git + autotools-configure-parameters: + - --prefix=/usr + - --disable-qt3 + - --disable-qt4 + - --disable-qt5 + - --disable-gtk + - --disable-gtk3 + - --disable-gdbm + - --disable-python + - --disable-pygtk + - --disable-python-dbus + - --disable-mono + - --disable-monodoc + - --disable-manpages + - --disable-xmltoman + - --with-avahi-user=_daemon_ + - --with-avahi-group=_daemon_ + # - --with-avahi-priv-access-group=netdev + # - --with-distro=debian + - --disable-gobject + - --datadir=/usr/share + - --libdir=/usr/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR} + - --with-systemdsystemunitdir=/usr/lib/systemd/system + - --localstatedir=/var + - --sysconfdir=/etc + build-packages: + - g++ + - gcc + - gettext + - intltool + - libdaemon-dev + - libdbus-1-dev + - libevent-dev + - libexpat1-dev + - libglib2.0-dev + - libsystemd-dev + - xmltoman + override-build: | + craftctl default + # for reference sort systemd service files + sed -i \ + -e 's|\(.*\)avahi-daemon -s.*|\1avahi-daemon -s --no-drop-root|g' \ + -e 's|\(.*\)avahi-daemon -r.*|\1avahi-daemon -r --no-drop-root|g' \ + ${CRAFT_PART_INSTALL}/usr/lib/systemd/system/avahi-daemon.service + mkdir -p \ + ${CRAFT_PART_INSTALL}/usr/lib/systemd/system/multi-user.target.wants + ln -sf \ + ../avahi-daemon.service \ + ${CRAFT_PART_INSTALL}/usr/lib/systemd/system/multi-user.target.wants/avahi-daemon.service + mkdir -p "${CRAFT_PART_INSTALL}/usr/share/dbus-1/" + cp -r /usr/share/dbus-1/* "${CRAFT_PART_INSTALL}/usr/share/dbus-1/" + build-environment: + - LD_LIBRARY_PATH: "${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$CRAFT_STAGE/usr/lib" + override-prime: | + set -eux + craftctl default + sed -i 's/use-ipv6=yes/use-ipv6=no/' ${CRAFT_PRIME}/etc/avahi/avahi-daemon.conf + sed -i 's|messagebus|_daemon_|; //,/<\/policy>/d' $CRAFT_PRIME/usr/share/dbus-1/system.conf + sed -i 's///g; s///g' $CRAFT_PRIME/usr/share/dbus-1/system.d/avahi-dbus.conf + stage-packages: + - libdaemon0 + - libevent-2.1-7 - avahi-utils - - libnss-mdns - mdns-scan + # - libavahi-client3 + # - libavahi-common3 + stage: + - etc/avahi + - usr + - -usr/lib/**/libavahi-client.so* + - -usr/lib/**/libavahi-common.so* + - -usr/lib/**/*.acd + - -usr/lib/**/*.la + - -usr/lib/**/avahi + - -usr/lib/**/libavahi-glib* + - -usr/lib/**/libavahi-libevent* + - -usr/lib/**/libevent-* + # - -usr/lib/**/libnss_mdns* + - -usr/lib/**/pkgconfig + - -usr/include + - -usr/share/doc + - -usr/share/man + - -usr/share/locale + after: [ipp-usb] + + utils: + plugin: nil + overlay-packages: + - python3 - dbus - - libavahi-client3 - - libavahi-common3 - override-build: | + - libnss-mdns + override-prime: | + set -eux craftctl default - mkdir -p "${CRAFT_PART_INSTALL}/usr/share/dbus-1/" - cp -r /usr/share/dbus-1/* "${CRAFT_PART_INSTALL}/usr/share/dbus-1/" + + # Set up Avahi Daemon runtime directory + AVAHI_RUN_DIR="$CRAFT_PRIME/var/run/avahi-daemon" + mkdir -p "$AVAHI_RUN_DIR" + chown 584792:584792 "$AVAHI_RUN_DIR" + chmod 777 "$AVAHI_RUN_DIR" + + # Set up D-Bus runtime directory + DBUS_RUN_DIR="$CRAFT_PRIME/var/run/dbus" + mkdir -p "$DBUS_RUN_DIR" + chown 584792:584792 "$DBUS_RUN_DIR" + chmod 777 "$DBUS_RUN_DIR" + + # Set up state directory for IPP-USB + STATE_DIR="$CRAFT_PRIME/var/lib/ipp-usb" + mkdir -p "$STATE_DIR" + chown 584792:584792 "$STATE_DIR" + chmod 770 "$STATE_DIR" + + # Set up IPP-USB runtime directories + IPP_USB_RUN_DIR="$CRAFT_PRIME/var/ipp-usb" + mkdir -p "$IPP_USB_RUN_DIR" + chown 584792:584792 "$IPP_USB_RUN_DIR" + chmod 770 "$IPP_USB_RUN_DIR" + + # Set up lock directory for IPP-USB + LOCK_DIR="$IPP_USB_RUN_DIR/lock" + mkdir -p "$LOCK_DIR" + chown 584792:584792 "$LOCK_DIR" + chmod 770 "$LOCK_DIR" + + # Set up log directory for IPP-USB + LOG_DIR="$CRAFT_PRIME/var/log/ipp-usb" + mkdir -p "$LOG_DIR" + chown 584792:584792 "$LOG_DIR" + chmod 770 "$LOG_DIR" + + DEV_DIR="$CRAFT_PRIME/var/dev" + mkdir -p "$DEV_DIR" + chown 584792:584792 "$DEV_DIR" + chmod 770 "$DEV_DIR" + + # Set up log file for IPP-USB + LOG_FILE="$LOG_DIR/main.log" + touch "$LOG_FILE" + chown 584792:584792 "$LOG_FILE" + chmod 644 "$LOG_FILE" + + # Set up /etc/ipp-usb directory for configuration files + CONF_DIR="$CRAFT_PRIME/etc/ipp-usb" + mkdir -p "$CONF_DIR" + chown 584792:584792 "$CONF_DIR" + chmod 770 "$CONF_DIR" + + # Set up /usr/share/ipp-usb/quirks directory + QUIRKS_DIR="$CRAFT_PRIME/usr/share/ipp-usb/quirks" + mkdir -p "$QUIRKS_DIR" + chown 584792:584792 "$QUIRKS_DIR" + chmod 770 "$QUIRKS_DIR" + + # Create default ipp-usb.conf file if missing + CONF_FILE="$CONF_DIR/ipp-usb.conf" + touch "$CONF_FILE" + chown 584792:584792 "$CONF_FILE" + chmod 644 "$CONF_FILE" + + # Ensure ipp-usb binary is executable and owned by _daemon_ + IPP_USB_BIN="$CRAFT_PRIME/usr/sbin/ipp-usb" + if [ -f "$IPP_USB_BIN" ]; then + chown root:584792 "$IPP_USB_BIN" # Owned by root, but executable by _daemon_ + chmod 750 "$IPP_USB_BIN" # Only root and _daemon_ can execute + chmod u+s "$IPP_USB_BIN" # Set SUID so it runs as root when executed + fi + after: [ipp-usb, avahi] scripts: plugin: dump source: scripts/ organize: run-ipp-usb.sh: scripts/run-ipp-usb.sh - run-dbus.sh: scripts/run-dbus.sh + run-avahi.sh: scripts/run-avahi.sh override-prime: | set -eux craftctl default if [ -f "$CRAFT_PRIME/scripts/run-ipp-usb.sh" ]; then chmod +x "$CRAFT_PRIME/scripts/run-ipp-usb.sh" fi - if [ -f "$CRAFT_PRIME/scripts/run-dbus.sh" ]; then - chmod +x "$CRAFT_PRIME/scripts/run-dbus.sh" + if [ -f "$CRAFT_PRIME/scripts/run-avahi.sh" ]; then + chmod +x "$CRAFT_PRIME/scripts/run-avahi.sh" fi - after: [ipp-usb, avahi-daemon] + after: [ipp-usb, avahi] diff --git a/rock/scripts/run-avahi.sh b/rock/scripts/run-avahi.sh new file mode 100644 index 0000000..2e539c1 --- /dev/null +++ b/rock/scripts/run-avahi.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -eux + +# Start dbus-daemon in the background +/usr/bin/dbus-daemon --system --nofork & + +# Wait for the D-Bus system bus to be ready +while [ ! -e /var/run/dbus/system_bus_socket ]; do + echo "Waiting for dbus-daemon to initialize..." + sleep 1 +done + +# Start avahi-daemon after dbus-daemon is ready +/usr/sbin/avahi-daemon -f /etc/avahi/avahi-daemon.conf --no-drop-root --debug + +# Keep the container running +exec tail -f /dev/null \ No newline at end of file diff --git a/rock/scripts/run-dbus.sh b/rock/scripts/run-dbus.sh deleted file mode 100644 index 11b902c..0000000 --- a/rock/scripts/run-dbus.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -set -eux - -echo "Creating system users..." - -# Check if users exist before attempting to create them -if ! id -u systemd-resolve >/dev/null 2>&1; then - useradd --system --no-create-home --shell /usr/sbin/nologin systemd-resolve -fi - -if ! id -u systemd-network >/dev/null 2>&1; then - useradd --system --no-create-home --shell /usr/sbin/nologin systemd-network -fi - -echo "Ensuring necessary directories exist..." - -# Ensure /run/dbus exists with correct permissions -if [ ! -d /run/dbus ]; then - mkdir -p /run/dbus - chmod 755 /run/dbus - chown root:root /run/dbus -fi - -echo "Starting dbus service..." - -# Start dbus and verify it's running -service dbus start -if ! pgrep -x "dbus-daemon" >/dev/null; then - echo "Failed to start dbus-daemon!" >&2 - exit 1 -fi - -echo "Starting avahi-daemon..." - -# Start avahi-daemon and ensure it's running -avahi-daemon --daemonize --no-drop-root -if ! pgrep -x "avahi-daemon" >/dev/null; then - echo "Failed to start avahi-daemon!" >&2 - exit 1 -fi - -echo "Services started successfully." - -# Keep the container alive using a foreground process -exec sleep infinity diff --git a/rock/scripts/run-ipp-usb.sh b/rock/scripts/run-ipp-usb.sh index 77cb8d1..58ff5d8 100644 --- a/rock/scripts/run-ipp-usb.sh +++ b/rock/scripts/run-ipp-usb.sh @@ -1,6 +1,6 @@ #!/bin/sh -#set -e -x +set -eux # Create needed directories (ignore errors) mkdir -p /etc/ipp-usb || : @@ -15,5 +15,18 @@ if [ ! -f /etc/ipp-usb/ipp-usb.conf ]; then cp /usr/share/ipp-usb/ipp-usb.conf /etc/ipp-usb/ >/dev/null 2>&1 || : fi +# Wait for avahi-daemon to initialize +while true; do + if [ -f "/var/run/avahi-daemon/pid" ] || [ -f "/run/avahi-daemon/pid" ]; then + echo "[$(date)] avahi-daemon is active. Starting ipp-usb..." + break + fi + echo "[$(date)] Waiting for avahi-daemon to initialize..." + sleep 1 +done + +# Run ipp-usb with logging +echo "[$(date)] Running ipp-usb..." + # Run ipp-usb with the provided command-line arguments exec /usr/sbin/ipp-usb "$@" From 44b2745fd2e4c200a78f7a3f72f4e703af48124f Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Thu, 20 Mar 2025 01:09:11 +0530 Subject: [PATCH 2/7] Updated ReadMe to include runtime flags for data persistence --- README.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ae0c9e9..13354d9 100644 --- a/README.md +++ b/README.md @@ -245,18 +245,24 @@ To pull the image from the GitHub Container Registry, run the following command: sudo docker pull ghcr.io/openprinting/ipp-usb:latest ``` +Create a Docker volume: +```sh + sudo docker volume create ipp-usb-data +``` + To run the container after pulling the image, use: ```sh sudo docker run -d --network host \ -v /dev/bus/usb:/dev/bus/usb:ro \ + -v ipp-usb-data:/var/lib/ipp-usb \ --device-cgroup-rule='c 189:* rmw' \ --name ipp-usb \ ghcr.io/openprinting/ipp-usb:latest ``` - -- `--network host`: Uses the host network, ensuring IPP-over-USB and Avahi service discovery work correctly. -- `-v /dev/bus/usb:/dev/bus/usb:ro`: Grants the container read-only access to USB devices. -- `--device-cgroup-rule='c 189:* rmw'`: Grants the container permission to manage USB devices (189:* covers USB device nodes). +- `--network host`: Uses the host’s network for IPP-over-USB and Avahi service discovery, enabling seamless printer detection. +- `-v /dev/bus/usb:/dev/bus/usb:ro`: Grants read-only access to USB devices, allowing the container to detect USB printers. +- `-v ipp-usb-data:/var/lib/ipp-usb`: Provides persistent storage for IPP-USB data, ensuring configuration and logs remain after restarts. +- `--device-cgroup-rule='c 189:* rmw'`: Allows read, write, and device management for USB printers inside the container. To check the logs of `ipp-usb`, run: ```sh @@ -292,7 +298,12 @@ Navigate to the directory containing `rockcraft.yaml`, then run: Once the `.rock` file is built, compile a Docker image from it using: ```sh - sudo rockcraft.skopeo --insecure-policy copy oci-archive: docker-daemon:ipp-usb:latest + sudo rockcraft.skopeo --insecure-policy copy oci-archive: docker-daemon:ipp-usb:latest +``` + +Create a Docker volume: +```sh + sudo docker volume create ipp-usb-data ``` **Run the `ipp-usb` Docker Container** @@ -300,10 +311,15 @@ Once the `.rock` file is built, compile a Docker image from it using: ```sh sudo docker run -d --network host \ -v /dev/bus/usb:/dev/bus/usb:ro \ + -v ipp-usb-data:/var/lib/ipp-usb \ --device-cgroup-rule='c 189:* rmw' \ --name ipp-usb \ ipp-usb:latest ``` +- `--network host`: Uses the host’s network for IPP-over-USB and Avahi service discovery, enabling seamless printer detection. +- `-v /dev/bus/usb:/dev/bus/usb:ro`: Grants read-only access to USB devices, allowing the container to detect USB printers. +- `-v ipp-usb-data:/var/lib/ipp-usb`: Provides persistent storage for IPP-USB data, ensuring configuration and logs remain after restarts. +- `--device-cgroup-rule='c 189:* rmw'`: Allows read, write, and device management for USB printers inside the container. ### Accessing the Container Shell @@ -313,22 +329,6 @@ To enter the running `ipp-usb` container and access a shell inside it, use: ``` This allows you to inspect logs, debug issues, or manually run commands inside the container. -### Configuration - -The `ipp-usb` container uses a configuration file located at: -``` -/etc/ipp-usb.conf -``` -To customize the configuration, mount a modified config file: -```sh - sudo docker run -d --network host \ - -v /dev/bus/usb:/dev/bus/usb:ro \ - --device-cgroup-rule='c 189:* rmw' \ - -v /path/to/custom/ipp-usb.conf:/etc/ipp-usb.conf:ro \ - --name ipp-usb \ - ghcr.io/openprinting/ipp-usb:latest -``` - ## Installation from source From 3d84e40f104db787e427a6838f5ae5294b70f00c Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Thu, 20 Mar 2025 10:12:18 +0530 Subject: [PATCH 3/7] Updated documentation for configuration and logging setup --- README.md | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/README.md b/README.md index 13354d9..747d61a 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,84 @@ To enter the running `ipp-usb` container and access a shell inside it, use: ``` This allows you to inspect logs, debug issues, or manually run commands inside the container. +### Configuration + +The `ipp-usb` container uses a configuration file located at: +```sh +/etc/ipp-usb/ipp-usb.conf +``` +By default, the container uses the built-in configuration, but you can override it by mounting a custom config file. + +#### **Mounting a Custom Configuration File** +To use a modified configuration file, you can mount it from the host system when starting the container: +```sh +sudo docker run -d --network host \ + -v /dev/bus/usb:/dev/bus/usb:ro \ + -v ipp-usb-data:/var/lib/ipp-usb \ + --device-cgroup-rule='c 189:* rmw' \ + -v /path/to/custom/ipp-usb.conf:/etc/ipp-usb/ipp-usb.conf:ro \ + --name ipp-usb \ + ghcr.io/openprinting/ipp-usb:latest +``` +- Replace `/path/to/custom/ipp-usb.conf` with the actual path to your modified config file. +- The `:ro` flag makes the file **read-only**, ensuring it cannot be modified inside the container. +- Any changes made to `/path/to/custom/ipp-usb.conf` on the host will apply when the container is restarted. + +#### **Editing the Configuration File on the Host** +Since the Rock image does not include text editors inside the container, you must edit the config file **on the host** before mounting it. +1. Open the config file with a text editor: + ```sh + nano /path/to/custom/ipp-usb.conf + ``` +2. Modify settings as needed and save the file. +3. Restart the container to apply changes: + ```sh + sudo docker restart ipp-usb + ``` + +### **Viewing Logs in the `ipp-usb` Container** + +The `ipp-usb` container logs important events and errors to `/var/log/ipp-usb/main.log`. Since the container is immutable, you need to either **mount the log directory** for persistence or **use Docker commands** to inspect logs. + +#### **1. Using Docker Logs** +To view real-time logs from the running container, use: +```sh +sudo docker logs -f ipp-usb +``` +- The `-f` flag follows the logs in real-time. +- Replace `ipp-usb` with your actual container name if different. + +#### **2. Accessing Logs Inside the Container** +If you need to inspect logs manually, enter the container shell: +```sh +sudo docker exec -it ipp-usb bash +``` +Then, inside the container, run: +```sh +cat /var/log/ipp-usb/main.log +``` + +#### **3. Persisting Logs by Mounting a Directory** +If you want logs to persist after container restarts, mount a host directory to store logs: +```sh +sudo docker run -d --network host \ + -v /dev/bus/usb:/dev/bus/usb:ro \ + -v ipp-usb-data:/var/lib/ipp-usb \ + -v /path/to/logs:/var/log/ipp-usb \ + --device-cgroup-rule='c 189:* rmw' \ + --name ipp-usb \ + ghcr.io/openprinting/ipp-usb:latest +``` +- Replace `/path/to/logs` with an actual directory on your host system. +- Logs will be available at `/path/to/logs/main.log` on the host. + +#### **4. Checking Logs Without Entering the Container** +If logs are mounted to a directory on the host, view them directly: +```sh +cat /path/to/logs/main.log +tail -f /path/to/logs/main.log # Follow logs in real-time +``` + ## Installation from source From f936a9b45a231711b1fad507ead7c5bafdc3af5a Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Thu, 20 Mar 2025 23:12:44 +0530 Subject: [PATCH 4/7] Include nano in Rock image and improve docs with persistent storage for ipp-usb --- README.md | 98 +++++++++++++------------------------ rock/rockcraft.yaml | 30 +++++------- rock/scripts/run-ipp-usb.sh | 4 +- 3 files changed, 50 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index 747d61a..303e4c7 100644 --- a/README.md +++ b/README.md @@ -245,23 +245,16 @@ To pull the image from the GitHub Container Registry, run the following command: sudo docker pull ghcr.io/openprinting/ipp-usb:latest ``` -Create a Docker volume: -```sh - sudo docker volume create ipp-usb-data -``` - To run the container after pulling the image, use: ```sh sudo docker run -d --network host \ -v /dev/bus/usb:/dev/bus/usb:ro \ - -v ipp-usb-data:/var/lib/ipp-usb \ --device-cgroup-rule='c 189:* rmw' \ --name ipp-usb \ ghcr.io/openprinting/ipp-usb:latest ``` - `--network host`: Uses the host’s network for IPP-over-USB and Avahi service discovery, enabling seamless printer detection. - `-v /dev/bus/usb:/dev/bus/usb:ro`: Grants read-only access to USB devices, allowing the container to detect USB printers. -- `-v ipp-usb-data:/var/lib/ipp-usb`: Provides persistent storage for IPP-USB data, ensuring configuration and logs remain after restarts. - `--device-cgroup-rule='c 189:* rmw'`: Allows read, write, and device management for USB printers inside the container. To check the logs of `ipp-usb`, run: @@ -301,24 +294,17 @@ Once the `.rock` file is built, compile a Docker image from it using: sudo rockcraft.skopeo --insecure-policy copy oci-archive: docker-daemon:ipp-usb:latest ``` -Create a Docker volume: -```sh - sudo docker volume create ipp-usb-data -``` - **Run the `ipp-usb` Docker Container** ```sh sudo docker run -d --network host \ -v /dev/bus/usb:/dev/bus/usb:ro \ - -v ipp-usb-data:/var/lib/ipp-usb \ --device-cgroup-rule='c 189:* rmw' \ --name ipp-usb \ ipp-usb:latest ``` - `--network host`: Uses the host’s network for IPP-over-USB and Avahi service discovery, enabling seamless printer detection. - `-v /dev/bus/usb:/dev/bus/usb:ro`: Grants read-only access to USB devices, allowing the container to detect USB printers. -- `-v ipp-usb-data:/var/lib/ipp-usb`: Provides persistent storage for IPP-USB data, ensuring configuration and logs remain after restarts. - `--device-cgroup-rule='c 189:* rmw'`: Allows read, write, and device management for USB printers inside the container. ### Accessing the Container Shell @@ -335,44 +321,41 @@ The `ipp-usb` container uses a configuration file located at: ```sh /etc/ipp-usb/ipp-usb.conf ``` -By default, the container uses the built-in configuration, but you can override it by mounting a custom config file. +By default, the container uses the built-in configuration, which can be modified from inside the container. + +### **Modifying the Configuration File Inside the Container** -#### **Mounting a Custom Configuration File** -To use a modified configuration file, you can mount it from the host system when starting the container: +#### **1 Enter the Running Container** +Use the following command to access the container’s shell: ```sh -sudo docker run -d --network host \ - -v /dev/bus/usb:/dev/bus/usb:ro \ - -v ipp-usb-data:/var/lib/ipp-usb \ - --device-cgroup-rule='c 189:* rmw' \ - -v /path/to/custom/ipp-usb.conf:/etc/ipp-usb/ipp-usb.conf:ro \ - --name ipp-usb \ - ghcr.io/openprinting/ipp-usb:latest +sudo docker exec -it ipp-usb bash +``` + +#### **2 Open the Configuration File in Nano** +Once inside the container, open the configuration file using `nano`: +```sh +nano /etc/ipp-usb/ipp-usb.conf +``` + +#### **3 Edit and Save the File** +- Make the necessary changes to the file. +- Press `CTRL + X`, then `Y`, and hit `Enter` to save the changes. + +#### **4 Restart the Container to Apply Changes** +Exit the container and restart it to apply the updated configuration: +```sh +sudo docker restart ipp-usb ``` -- Replace `/path/to/custom/ipp-usb.conf` with the actual path to your modified config file. -- The `:ro` flag makes the file **read-only**, ensuring it cannot be modified inside the container. -- Any changes made to `/path/to/custom/ipp-usb.conf` on the host will apply when the container is restarted. - -#### **Editing the Configuration File on the Host** -Since the Rock image does not include text editors inside the container, you must edit the config file **on the host** before mounting it. -1. Open the config file with a text editor: - ```sh - nano /path/to/custom/ipp-usb.conf - ``` -2. Modify settings as needed and save the file. -3. Restart the container to apply changes: - ```sh - sudo docker restart ipp-usb - ``` ### **Viewing Logs in the `ipp-usb` Container** -The `ipp-usb` container logs important events and errors to `/var/log/ipp-usb/main.log`. Since the container is immutable, you need to either **mount the log directory** for persistence or **use Docker commands** to inspect logs. +The `ipp-usb` container logs important events and errors to `/var/log/ipp-usb/main.log`. Since the container is immutable, logs are stored inside the container and can be accessed using Docker commands. #### **1. Using Docker Logs** To view real-time logs from the running container, use: ```sh sudo docker logs -f ipp-usb -``` +``` - The `-f` flag follows the logs in real-time. - Replace `ipp-usb` with your actual container name if different. @@ -380,32 +363,21 @@ sudo docker logs -f ipp-usb If you need to inspect logs manually, enter the container shell: ```sh sudo docker exec -it ipp-usb bash -``` +``` Then, inside the container, run: ```sh -cat /var/log/ipp-usb/main.log -``` - -#### **3. Persisting Logs by Mounting a Directory** -If you want logs to persist after container restarts, mount a host directory to store logs: +tail -f /var/log/ipp-usb/main.log +``` +This will display new log entries in real-time. If you only want to see the last few lines, use: ```sh -sudo docker run -d --network host \ - -v /dev/bus/usb:/dev/bus/usb:ro \ - -v ipp-usb-data:/var/lib/ipp-usb \ - -v /path/to/logs:/var/log/ipp-usb \ - --device-cgroup-rule='c 189:* rmw' \ - --name ipp-usb \ - ghcr.io/openprinting/ipp-usb:latest -``` -- Replace `/path/to/logs` with an actual directory on your host system. -- Logs will be available at `/path/to/logs/main.log` on the host. - -#### **4. Checking Logs Without Entering the Container** -If logs are mounted to a directory on the host, view them directly: +tail -n 50 /var/log/ipp-usb/main.log +``` +To view the full log file at once, use: ```sh -cat /path/to/logs/main.log -tail -f /path/to/logs/main.log # Follow logs in real-time -``` +cat /var/log/ipp-usb/main.log +``` + +Using `tail -f` is preferable for continuous monitoring, whereas `cat` is better for quick one-time checks. ## Installation from source diff --git a/rock/rockcraft.yaml b/rock/rockcraft.yaml index 0ce1978..26a8d01 100644 --- a/rock/rockcraft.yaml +++ b/rock/rockcraft.yaml @@ -210,6 +210,7 @@ parts: - python3 - dbus - libnss-mdns + - nano override-prime: | set -eux craftctl default @@ -226,12 +227,6 @@ parts: chown 584792:584792 "$DBUS_RUN_DIR" chmod 777 "$DBUS_RUN_DIR" - # Set up state directory for IPP-USB - STATE_DIR="$CRAFT_PRIME/var/lib/ipp-usb" - mkdir -p "$STATE_DIR" - chown 584792:584792 "$STATE_DIR" - chmod 770 "$STATE_DIR" - # Set up IPP-USB runtime directories IPP_USB_RUN_DIR="$CRAFT_PRIME/var/ipp-usb" mkdir -p "$IPP_USB_RUN_DIR" @@ -244,17 +239,18 @@ parts: chown 584792:584792 "$LOCK_DIR" chmod 770 "$LOCK_DIR" + # Set up lock directory for IPP-USB + DEV_DIR="$IPP_USB_RUN_DIR/dev" + mkdir -p "$DEV_DIR" + chown 584792:584792 "$DEV_DIR" + chmod 770 "$DEV_DIR" + # Set up log directory for IPP-USB LOG_DIR="$CRAFT_PRIME/var/log/ipp-usb" mkdir -p "$LOG_DIR" chown 584792:584792 "$LOG_DIR" chmod 770 "$LOG_DIR" - DEV_DIR="$CRAFT_PRIME/var/dev" - mkdir -p "$DEV_DIR" - chown 584792:584792 "$DEV_DIR" - chmod 770 "$DEV_DIR" - # Set up log file for IPP-USB LOG_FILE="$LOG_DIR/main.log" touch "$LOG_FILE" @@ -267,18 +263,18 @@ parts: chown 584792:584792 "$CONF_DIR" chmod 770 "$CONF_DIR" - # Set up /usr/share/ipp-usb/quirks directory - QUIRKS_DIR="$CRAFT_PRIME/usr/share/ipp-usb/quirks" - mkdir -p "$QUIRKS_DIR" - chown 584792:584792 "$QUIRKS_DIR" - chmod 770 "$QUIRKS_DIR" - # Create default ipp-usb.conf file if missing CONF_FILE="$CONF_DIR/ipp-usb.conf" touch "$CONF_FILE" chown 584792:584792 "$CONF_FILE" chmod 644 "$CONF_FILE" + # Set up /usr/share/ipp-usb/quirks directory + QUIRKS_DIR="$CRAFT_PRIME/usr/share/ipp-usb/quirks" + mkdir -p "$QUIRKS_DIR" + chown 584792:584792 "$QUIRKS_DIR" + chmod 770 "$QUIRKS_DIR" + # Ensure ipp-usb binary is executable and owned by _daemon_ IPP_USB_BIN="$CRAFT_PRIME/usr/sbin/ipp-usb" if [ -f "$IPP_USB_BIN" ]; then diff --git a/rock/scripts/run-ipp-usb.sh b/rock/scripts/run-ipp-usb.sh index 58ff5d8..758cb1e 100644 --- a/rock/scripts/run-ipp-usb.sh +++ b/rock/scripts/run-ipp-usb.sh @@ -5,8 +5,8 @@ set -eux # Create needed directories (ignore errors) mkdir -p /etc/ipp-usb || : mkdir -p /var/log/ipp-usb || : -mkdir -p /var/lock || : -mkdir -p /var/dev || : +mkdir -p /var/ipp-usb/lock || : +mkdir -p /var/ipp-usb/dev || : mkdir -p /usr/share/ipp-usb/quirks || : # Put config files in place (do not overwrite existing user config) From b932a99be39bc08e5de1fa80122c5c8028e9156d Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Thu, 20 Mar 2025 23:26:58 +0530 Subject: [PATCH 5/7] Updated Documentation and Rockcraft file --- README.md | 144 +++++++++++++++++++++++++------------------- rock/rockcraft.yaml | 2 +- 2 files changed, 83 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 303e4c7..7e51e78 100644 --- a/README.md +++ b/README.md @@ -235,77 +235,96 @@ start ipp-usb when needed. sudo snap install docker ``` -#### Step-by-Step Guide +### **Running the `ipp-usb` Container with Persistent Storage** -You can pull the `ipp-usb` Docker image from the GitHub Container Registry. +To run the `ipp-usb` container while ensuring that its state persists across restarts, follow these steps. -**From GitHub Container Registry**
-To pull the image from the GitHub Container Registry, run the following command: +#### **1. Pull the `ipp-usb` Docker Image** +The latest image is available on the GitHub Container Registry. Pull it using: ```sh sudo docker pull ghcr.io/openprinting/ipp-usb:latest -``` +``` -To run the container after pulling the image, use: +#### **2. Create a Persistent Storage Volume** +`ipp-usb` maintains important state files that should persist across container restarts. Create a Docker volume for this: ```sh - sudo docker run -d --network host \ - -v /dev/bus/usb:/dev/bus/usb:ro \ - --device-cgroup-rule='c 189:* rmw' \ - --name ipp-usb \ - ghcr.io/openprinting/ipp-usb:latest -``` -- `--network host`: Uses the host’s network for IPP-over-USB and Avahi service discovery, enabling seamless printer detection. -- `-v /dev/bus/usb:/dev/bus/usb:ro`: Grants read-only access to USB devices, allowing the container to detect USB printers. -- `--device-cgroup-rule='c 189:* rmw'`: Allows read, write, and device management for USB printers inside the container. + sudo docker volume create ipp-usb-storage +``` +This volume will store: +- **Persistent state files** (`/var/ipp-usb/dev/`) – Ensures stable TCP port allocation and DNS-SD name resolution. +- **Lock files** (`/var/ipp-usb/lock/`) – Prevents multiple instances from running simultaneously. -To check the logs of `ipp-usb`, run: + +#### **3. Run the Container with Required Mounts** +Start the container with the necessary options: ```sh - sudo docker logs -f ipp-usb -``` +sudo docker run -d --network host \ + -v /dev/bus/usb:/dev/bus/usb:ro \ + -v ipp-usb-storage:/var/ipp-usb \ + --device-cgroup-rule='c 189:* rmw' \ + --name ipp-usb \ + ghcr.io/openprinting/ipp-usb:latest +``` + +- **`--network host`** → Uses the host’s network for proper IPP-over-USB and Avahi service discovery. +- **`-v /dev/bus/usb:/dev/bus/usb:ro`** → Grants read-only access to USB devices, allowing printer detection. +- **`-v ipp-usb-storage:/var/ipp-usb`** → Mounts the persistent storage volume, ensuring printer state persists across reboots. +- **`--device-cgroup-rule='c 189:* rmw'`** → Grants read, write, and management permissions for USB printers inside the container. ### Building and Running `ipp-usb` Locally #### Prerequisites -**Docker Installed**: Ensure Docker is installed on your system. You can download it from the [official Docker website](https://www.docker.com/get-started) or from the Snap Store: +1. **Docker Installed**: Ensure Docker is installed on your system. You can download it from the [official Docker website](https://www.docker.com/get-started) or from the Snap Store: ```sh sudo snap install docker ``` -**Rockcraft**: Rockcraft should be installed. You can install Rockcraft using the following command: +2. **Rockcraft**: Rockcraft should be installed. You can install Rockcraft using the following command: ```sh sudo snap install rockcraft --classic ``` -#### Step-by-Step Guide +**To Build and Run the `ipp-usb` Rock Image Locally, follow these steps** -**Build the `ipp-usb` Rock Image** +#### **1. Build the `ipp-usb` Rock Image** +The first step is to build the Rock image from the `rockcraft.yaml` configuration file. This image will include all required dependencies and configurations for `ipp-usb`. -The first step is to build the Rock from the `rockcraft.yaml`. This image will contain all the configurations and dependencies required to run `ipp-usb`. - -Navigate to the directory containing `rockcraft.yaml`, then run: +Navigate to the directory containing `rockcraft.yaml` and run: ```sh rockcraft pack -v -``` - -**Compile to Docker Image** +``` -Once the `.rock` file is built, compile a Docker image from it using: +#### **2. Convert the Rock Image to a Docker Image** +Once the `.rock` file is built, convert it into a Docker image using: ```sh - sudo rockcraft.skopeo --insecure-policy copy oci-archive: docker-daemon:ipp-usb:latest -``` +sudo rockcraft.skopeo --insecure-policy copy oci-archive: docker-daemon:ipp-usb:latest +``` -**Run the `ipp-usb` Docker Container** +#### **3. Create a Persistent Storage Volume** +To maintain state across restarts, create a Docker volume for `ipp-usb`: +```sh +sudo docker volume create ipp-usb-storage +``` +This volume stores: +- **Persistent state files** (`/var/ipp-usb/dev/`) – Ensures stable TCP port allocation and DNS-SD name resolution. +- **Lock files** (`/var/ipp-usb/lock/`) – Prevents multiple instances from running simultaneously. +#### **4. Run the Container with Required Mounts** +Start the `ipp-usb` container locally using: ```sh - sudo docker run -d --network host \ - -v /dev/bus/usb:/dev/bus/usb:ro \ - --device-cgroup-rule='c 189:* rmw' \ - --name ipp-usb \ - ipp-usb:latest -``` -- `--network host`: Uses the host’s network for IPP-over-USB and Avahi service discovery, enabling seamless printer detection. -- `-v /dev/bus/usb:/dev/bus/usb:ro`: Grants read-only access to USB devices, allowing the container to detect USB printers. -- `--device-cgroup-rule='c 189:* rmw'`: Allows read, write, and device management for USB printers inside the container. +sudo docker run -d --network host \ + -v /dev/bus/usb:/dev/bus/usb:ro \ + -v ipp-usb-storage:/var/ipp-usb \ + --device-cgroup-rule='c 189:* rmw' \ + --name ipp-usb \ + ipp-usb:latest +``` + +- **`--network host`** → Uses the host’s network for proper IPP-over-USB and Avahi service discovery. +- **`-v /dev/bus/usb:/dev/bus/usb:ro`** → Grants read-only access to USB devices, allowing printer detection. +- **`-v ipp-usb-storage:/var/ipp-usb`** → Mounts the persistent storage volume, ensuring printer state persists across reboots. +- **`--device-cgroup-rule='c 189:* rmw'`** → Grants read, write, and management permissions for USB printers inside the container. ### Accessing the Container Shell @@ -323,25 +342,25 @@ The `ipp-usb` container uses a configuration file located at: ``` By default, the container uses the built-in configuration, which can be modified from inside the container. -### **Modifying the Configuration File Inside the Container** +**Modifying the Configuration File Inside the Container** -#### **1 Enter the Running Container** +#### **1. Enter the Running Container** Use the following command to access the container’s shell: ```sh sudo docker exec -it ipp-usb bash ``` -#### **2 Open the Configuration File in Nano** +#### **2. Open the Configuration File in Nano** Once inside the container, open the configuration file using `nano`: ```sh nano /etc/ipp-usb/ipp-usb.conf ``` -#### **3 Edit and Save the File** +#### **3. Edit and Save the File** - Make the necessary changes to the file. - Press `CTRL + X`, then `Y`, and hit `Enter` to save the changes. -#### **4 Restart the Container to Apply Changes** +#### **4. Restart the Container to Apply Changes** Exit the container and restart it to apply the updated configuration: ```sh sudo docker restart ipp-usb @@ -349,7 +368,7 @@ sudo docker restart ipp-usb ### **Viewing Logs in the `ipp-usb` Container** -The `ipp-usb` container logs important events and errors to `/var/log/ipp-usb/main.log`. Since the container is immutable, logs are stored inside the container and can be accessed using Docker commands. +The `ipp-usb` container logs important events and errors to `/var/log/ipp-usb/main.log`. Since the container is immutable, logs are stored inside the container and can be accessed using Docker commands. #### **1. Using Docker Logs** To view real-time logs from the running container, use: @@ -359,25 +378,26 @@ sudo docker logs -f ipp-usb - The `-f` flag follows the logs in real-time. - Replace `ipp-usb` with your actual container name if different. -#### **2. Accessing Logs Inside the Container** -If you need to inspect logs manually, enter the container shell: +#### **2. Viewing Logs Inside the Container** + +To inspect logs manually, first enter the container shell: ```sh sudo docker exec -it ipp-usb bash ``` -Then, inside the container, run: -```sh -tail -f /var/log/ipp-usb/main.log -``` -This will display new log entries in real-time. If you only want to see the last few lines, use: -```sh -tail -n 50 /var/log/ipp-usb/main.log -``` -To view the full log file at once, use: -```sh -cat /var/log/ipp-usb/main.log -``` -Using `tail -f` is preferable for continuous monitoring, whereas `cat` is better for quick one-time checks. +Once inside the container, use one of the following methods: + +- **Monitor logs in real-time:** + ```sh + tail -f /var/log/ipp-usb/main.log + ``` + This continuously displays new log entries as they appear. + +- **Display the full log file at once:** + ```sh + cat /var/log/ipp-usb/main.log + ``` + Best for reviewing the complete log content. ## Installation from source diff --git a/rock/rockcraft.yaml b/rock/rockcraft.yaml index 26a8d01..5453eae 100644 --- a/rock/rockcraft.yaml +++ b/rock/rockcraft.yaml @@ -239,7 +239,7 @@ parts: chown 584792:584792 "$LOCK_DIR" chmod 770 "$LOCK_DIR" - # Set up lock directory for IPP-USB + # Set up dev directory for IPP-USB DEV_DIR="$IPP_USB_RUN_DIR/dev" mkdir -p "$DEV_DIR" chown 584792:584792 "$DEV_DIR" From a4090b0db2e699f900f19e0a8cab5f51f596463f Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Sat, 22 Mar 2025 10:45:42 +0530 Subject: [PATCH 6/7] Enhanced persistence: Separate volumes for state, config, and logs in ipp-usb. --- README.md | 132 ++++++++++++++++++++++++++---------- rock/rockcraft.yaml | 10 +-- rock/scripts/run-ipp-usb.sh | 21 +++--- 3 files changed, 107 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 7e51e78..4b895ad 100644 --- a/README.md +++ b/README.md @@ -235,42 +235,55 @@ start ipp-usb when needed. sudo snap install docker ``` -### **Running the `ipp-usb` Container with Persistent Storage** +#### **Running the `ipp-usb` Container with Persistent Storage** To run the `ipp-usb` container while ensuring that its state persists across restarts, follow these steps. #### **1. Pull the `ipp-usb` Docker Image** The latest image is available on the GitHub Container Registry. Pull it using: ```sh - sudo docker pull ghcr.io/openprinting/ipp-usb:latest -``` +sudo docker pull ghcr.io/openprinting/ipp-usb:latest +``` + +#### **2. Create Persistent Storage Volumes** +To ensure that configuration settings and printer state persist across container restarts, create two Docker volumes: -#### **2. Create a Persistent Storage Volume** -`ipp-usb` maintains important state files that should persist across container restarts. Create a Docker volume for this: ```sh - sudo docker volume create ipp-usb-storage +sudo docker volume create ipp-usb-state +sudo docker volume create ipp-usb-conf ``` -This volume will store: -- **Persistent state files** (`/var/ipp-usb/dev/`) – Ensures stable TCP port allocation and DNS-SD name resolution. -- **Lock files** (`/var/ipp-usb/lock/`) – Prevents multiple instances from running simultaneously. +These volumes store: + +- **`ipp-usb-state` (`/var/ipp-usb/`)** + - Device state files (`/var/ipp-usb/dev/`) – Ensures stable TCP port allocation and DNS-SD name resolution. + - Lock files (`/var/ipp-usb/lock/`) – Prevents multiple instances from running simultaneously. + - Log files (`/var/log/ipp-usb/`) – Can be optionally mounted if needed for debugging. + +- **`ipp-usb-conf` (`/etc/ipp-usb/`)** + - Configuration file (`/etc/ipp-usb/ipp-usb.conf`) – Stores user-defined settings. + - Quirks files (`/etc/ipp-usb/quirks/`) – Contains printer-specific workarounds. #### **3. Run the Container with Required Mounts** -Start the container with the necessary options: +Start the container with appropriate options: + ```sh sudo docker run -d --network host \ -v /dev/bus/usb:/dev/bus/usb:ro \ - -v ipp-usb-storage:/var/ipp-usb \ + -v ipp-usb-state:/var/ipp-usb \ + -v ipp-usb-conf:/etc/ipp-usb \ --device-cgroup-rule='c 189:* rmw' \ --name ipp-usb \ ghcr.io/openprinting/ipp-usb:latest -``` - -- **`--network host`** → Uses the host’s network for proper IPP-over-USB and Avahi service discovery. -- **`-v /dev/bus/usb:/dev/bus/usb:ro`** → Grants read-only access to USB devices, allowing printer detection. -- **`-v ipp-usb-storage:/var/ipp-usb`** → Mounts the persistent storage volume, ensuring printer state persists across reboots. +``` + +- **`--network host`** → Uses the host’s network to enable proper IPP-over-USB and Avahi service discovery. +- **`-v /dev/bus/usb:/dev/bus/usb:ro`** → Grants read-only access to USB devices for printer detection. +- **`-v ipp-usb-state:/var/ipp-usb`** → Mounts the persistent storage volume for printer state, lock files, and logs. +- **`-v ipp-usb-conf:/etc/ipp-usb`** → Ensures configuration and quirks files persist across reboots. - **`--device-cgroup-rule='c 189:* rmw'`** → Grants read, write, and management permissions for USB printers inside the container. + ### Building and Running `ipp-usb` Locally #### Prerequisites @@ -301,29 +314,42 @@ Once the `.rock` file is built, convert it into a Docker image using: sudo rockcraft.skopeo --insecure-policy copy oci-archive: docker-daemon:ipp-usb:latest ``` -#### **3. Create a Persistent Storage Volume** -To maintain state across restarts, create a Docker volume for `ipp-usb`: +#### **3. Create Persistent Storage Volumes** +To ensure that configuration settings and printer state persist across container restarts, create two Docker volumes: + ```sh -sudo docker volume create ipp-usb-storage +sudo docker volume create ipp-usb-state +sudo docker volume create ipp-usb-conf ``` -This volume stores: -- **Persistent state files** (`/var/ipp-usb/dev/`) – Ensures stable TCP port allocation and DNS-SD name resolution. -- **Lock files** (`/var/ipp-usb/lock/`) – Prevents multiple instances from running simultaneously. + +These volumes store: + +- **`ipp-usb-state` (`/var/ipp-usb/`)** + - Device state files (`/var/ipp-usb/dev/`) – Ensures stable TCP port allocation and DNS-SD name resolution. + - Lock files (`/var/ipp-usb/lock/`) – Prevents multiple instances from running simultaneously. + - Log files (`/var/log/ipp-usb/`) – Can be optionally mounted if needed for debugging. + +- **`ipp-usb-conf` (`/etc/ipp-usb/`)** + - Configuration file (`/etc/ipp-usb/ipp-usb.conf`) – Stores user-defined settings. + - Quirks files (`/etc/ipp-usb/quirks/`) – Contains printer-specific workarounds. #### **4. Run the Container with Required Mounts** -Start the `ipp-usb` container locally using: +Start the container with appropriate options: + ```sh sudo docker run -d --network host \ -v /dev/bus/usb:/dev/bus/usb:ro \ - -v ipp-usb-storage:/var/ipp-usb \ + -v ipp-usb-state:/var/ipp-usb \ + -v ipp-usb-conf:/etc/ipp-usb \ --device-cgroup-rule='c 189:* rmw' \ --name ipp-usb \ ipp-usb:latest -``` - -- **`--network host`** → Uses the host’s network for proper IPP-over-USB and Avahi service discovery. -- **`-v /dev/bus/usb:/dev/bus/usb:ro`** → Grants read-only access to USB devices, allowing printer detection. -- **`-v ipp-usb-storage:/var/ipp-usb`** → Mounts the persistent storage volume, ensuring printer state persists across reboots. +``` + +- **`--network host`** → Uses the host’s network to enable proper IPP-over-USB and Avahi service discovery. +- **`-v /dev/bus/usb:/dev/bus/usb:ro`** → Grants read-only access to USB devices for printer detection. +- **`-v ipp-usb-state:/var/ipp-usb`** → Mounts the persistent storage volume for printer state, lock files, and logs. +- **`-v ipp-usb-conf:/etc/ipp-usb`** → Ensures configuration and quirks files persist across reboots. - **`--device-cgroup-rule='c 189:* rmw'`** → Grants read, write, and management permissions for USB printers inside the container. ### Accessing the Container Shell @@ -368,9 +394,13 @@ sudo docker restart ipp-usb ### **Viewing Logs in the `ipp-usb` Container** -The `ipp-usb` container logs important events and errors to `/var/log/ipp-usb/main.log`. Since the container is immutable, logs are stored inside the container and can be accessed using Docker commands. +The `ipp-usb` container logs important events and errors to `/var/log/ipp-usb/`. Logs are categorized into: + +- **Main log file:** `/var/log/ipp-usb/main.log` → Captures overall service activity, including errors and general events. +- **Per-device logs:** `/var/log/ipp-usb/.log` → Individual log files for each detected printer, helpful for troubleshooting device-specific issues. #### **1. Using Docker Logs** + To view real-time logs from the running container, use: ```sh sudo docker logs -f ipp-usb @@ -380,25 +410,55 @@ sudo docker logs -f ipp-usb #### **2. Viewing Logs Inside the Container** -To inspect logs manually, first enter the container shell: +If you need to inspect logs manually, first enter the container shell: ```sh sudo docker exec -it ipp-usb bash ``` -Once inside the container, use one of the following methods: +Once inside the container, you can use the following commands: + +#### **2.1 Monitor Logs in Real-Time** -- **Monitor logs in real-time:** +- **Main log file:** ```sh tail -f /var/log/ipp-usb/main.log ``` - This continuously displays new log entries as they appear. + This continuously displays new log entries for the entire service. -- **Display the full log file at once:** +- **Per-device log file (Replace `` with your printer's identifier):** + ```sh + tail -f /var/log/ipp-usb/.log + ``` + +#### **2.2 Display Full Log Files** + +- **Show full contents of the main log file:** ```sh cat /var/log/ipp-usb/main.log ``` - Best for reviewing the complete log content. +- **Show logs for a specific device:** + ```sh + cat /var/log/ipp-usb/.log + ``` + +#### **2.3 List Available Device Logs** + +To see all available per-device log files, run: +```sh +ls /var/log/ipp-usb/ +``` + +#### **3. Persisting Logs Across Container Restarts** + +If you want logs to persist across container restarts, you should mount the log directory using a Docker volume or a host directory. + +**Required Docker Flags for Log Persistence:** +- `-v :/var/log/ipp-usb` → Mounts a Docker volume for log persistence. +- **or** +- `-v :/var/log/ipp-usb` → Mounts a host directory to retain logs outside the container. + +These options ensure that logs remain available even after the container stops or is recreated, allowing for easier troubleshooting and auditing. ## Installation from source diff --git a/rock/rockcraft.yaml b/rock/rockcraft.yaml index 5453eae..7bb9f9f 100644 --- a/rock/rockcraft.yaml +++ b/rock/rockcraft.yaml @@ -251,12 +251,6 @@ parts: chown 584792:584792 "$LOG_DIR" chmod 770 "$LOG_DIR" - # Set up log file for IPP-USB - LOG_FILE="$LOG_DIR/main.log" - touch "$LOG_FILE" - chown 584792:584792 "$LOG_FILE" - chmod 644 "$LOG_FILE" - # Set up /etc/ipp-usb directory for configuration files CONF_DIR="$CRAFT_PRIME/etc/ipp-usb" mkdir -p "$CONF_DIR" @@ -269,8 +263,8 @@ parts: chown 584792:584792 "$CONF_FILE" chmod 644 "$CONF_FILE" - # Set up /usr/share/ipp-usb/quirks directory - QUIRKS_DIR="$CRAFT_PRIME/usr/share/ipp-usb/quirks" + # Set up quirks directory + QUIRKS_DIR="$CRAFT_PRIME/etc/ipp-usb/quirks" mkdir -p "$QUIRKS_DIR" chown 584792:584792 "$QUIRKS_DIR" chmod 770 "$QUIRKS_DIR" diff --git a/rock/scripts/run-ipp-usb.sh b/rock/scripts/run-ipp-usb.sh index 758cb1e..56257bf 100644 --- a/rock/scripts/run-ipp-usb.sh +++ b/rock/scripts/run-ipp-usb.sh @@ -1,21 +1,21 @@ #!/bin/sh - set -eux -# Create needed directories (ignore errors) +# Create necessary directories mkdir -p /etc/ipp-usb || : -mkdir -p /var/log/ipp-usb || : +mkdir -p /etc/ipp-usb/quirks || : mkdir -p /var/ipp-usb/lock || : mkdir -p /var/ipp-usb/dev || : -mkdir -p /usr/share/ipp-usb/quirks || : +mkdir -p /var/log/ipp-usb || : +# Copy quirks files if not present +cp -rn /usr/share/ipp-usb/quirks/* /etc/ipp-usb/quirks/ >/dev/null 2>&1 || : # Put config files in place (do not overwrite existing user config) -yes no | cp -i /usr/share/ipp-usb/quirks/* /etc/ipp-usb/quirks >/dev/null 2>&1 || : if [ ! -f /etc/ipp-usb/ipp-usb.conf ]; then - cp /usr/share/ipp-usb/ipp-usb.conf /etc/ipp-usb/ >/dev/null 2>&1 || : + cp /etc/ipp-usb.conf /etc/ipp-usb/ >/dev/null 2>&1 fi -# Wait for avahi-daemon to initialize +# Wait for avahi-daemon while true; do if [ -f "/var/run/avahi-daemon/pid" ] || [ -f "/run/avahi-daemon/pid" ]; then echo "[$(date)] avahi-daemon is active. Starting ipp-usb..." @@ -25,8 +25,5 @@ while true; do sleep 1 done -# Run ipp-usb with logging -echo "[$(date)] Running ipp-usb..." - -# Run ipp-usb with the provided command-line arguments -exec /usr/sbin/ipp-usb "$@" +# Start ipp-usb +exec /usr/sbin/ipp-usb From 0fde002b50cf9c08da4110919029f49ff62c1007 Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Sat, 22 Mar 2025 10:59:43 +0530 Subject: [PATCH 7/7] Updated run-ipp-usb script --- rock/scripts/run-ipp-usb.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rock/scripts/run-ipp-usb.sh b/rock/scripts/run-ipp-usb.sh index 56257bf..074fba7 100644 --- a/rock/scripts/run-ipp-usb.sh +++ b/rock/scripts/run-ipp-usb.sh @@ -25,5 +25,8 @@ while true; do sleep 1 done -# Start ipp-usb -exec /usr/sbin/ipp-usb +# Run ipp-usb with logging +echo "[$(date)] Running ipp-usb..." + +# Run ipp-usb with the provided command-line arguments +exec /usr/sbin/ipp-usb "$@"