sbs20 / scanservjs

SANE scanner nodejs web ui
https://sbs20.github.io/scanservjs/
GNU General Public License v2.0
762 stars 145 forks source link

dbus service restart in container conflicts with host services #380

Closed leandrotoledo closed 2 years ago

leandrotoledo commented 2 years ago

Hi there,

Let me start saying this is the most awesome self hosted service I came across, you gave new life for my old scanner and I really appreciate that.

There's one small issue that I've notice though. And this is completely shot in the dark while I'm still trying to fully understand what's going on.

When scanservjs starts, it seems like it also (re-)start the dbus service, thus recreating a new session and PID for the container. The problem with that is the local host user loses the reference of the original session and dependent services suddenly start to fail; at least that's my initial assumption.

To Reproduce Steps to reproduce the behavior:

  1. Start scanservjs service on docker
  2. Wait until dbus service and PID is re-createtd
  3. Try to start a different docker container, like nginx
  4. See error:
    docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:385: applying cgroup configuration for process caused: error while starting unit "docker-206de6961f1cea12a0fe1c260df7b0418caf4d4aaaae7192b9a64c1c0b63b2a4.scope" with properties [{Name:Description Value:"libcontainer container 206de6961f1cea12a0fe1c260df7b0418caf4d4aaaae7192b9a64c1c0b63b2a4"} {Name:Slice Value:"system.slice"} {Name:PIDs Value:@au [32193]} {Name:Delegate Value:true} {Name:MemoryAccounting Value:true} {Name:CPUAccounting Value:true} {Name:IOAccounting Value:true} {Name:TasksAccounting Value:true} {Name:DefaultDependencies Value:false}]: The name org.freedesktop.systemd1 was not provided by any .service files: unknown.
  5. Inspect systemctl -l, see error:
    Failed to connect to bus: Connection refused
  6. XDG env vars are gone:
    SHELL=/bin/bash
    MOTD_SHOWN=pam
    LANG=en_US.UTF-8
    ...
    TERM=xterm-256color
    SHLVL=1
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    SSH_TTY=/dev/pts/0
    _=/usr/bin/env

Workaround Stop container, reboot the host.

Server (please complete the following information):

docker-compose.yml

services:
  scanservjs:
    container_name: scanservjs
    image: sbs20/scanservjs:latest
    restart: always
    ports:
      - 5080:8080
    volumes:
      - ./data/scans:/app/data/output
      - /var/run/dbus:/var/run/dbus <--------
    environment:
      - AIRSCAN_DEVICES="HP Neverstop Laser MFP 1202w" = "http://printer.xxx/eSCL"
      - DEVICES=airscan:e0:HP Neverstop Laser MFP 1202w
    network_mode:
      bridge

Logs if in docker

docker logs scanservjs-container

scanservjs    |
scanservjs    | # Test using the following form:
scanservjs    | # export SANED_NET_HOSTS="a|b" AIRSCAN_DEVICES="c|d" DELIMITER="|"; ./run.sh
scanservjs    |
scanservjs    | # turn off globbing
scanservjs    | set -f
scanservjs    | + set -f
scanservjs    |
scanservjs    | # split at newlines only (airscan devices can have spaces in)
scanservjs    | IFS='
scanservjs    | '
scanservjs    | + IFS=
scanservjs    |
scanservjs    |
scanservjs    | # Get a custom delimiter but default to ;
scanservjs    | DELIMITER=${DELIMITER:-;}
scanservjs    | + DELIMITER=;
scanservjs    |
scanservjs    | # Insert a list of net hosts
scanservjs    | if [ ! -z "$SANED_NET_HOSTS" ]; then
scanservjs    |   hosts=$(echo $SANED_NET_HOSTS | sed "s/$DELIMITER/\n/")
scanservjs    |   for host in $hosts; do
scanservjs    |     echo $host >> /etc/sane.d/net.conf
scanservjs    |   done
scanservjs    | fi
scanservjs    | + [ ! -z  ]
scanservjs    |
scanservjs    | # Insert airscan devices
scanservjs    | if [ ! -z "$AIRSCAN_DEVICES" ]; then
scanservjs    |   devices=$(echo $AIRSCAN_DEVICES | sed "s/$DELIMITER/\n/")
scanservjs    |   for device in $devices; do
scanservjs    |     sed -i "/^\[devices\]/a $device" /etc/sane.d/airscan.conf
scanservjs    |   done
scanservjs    | fi
scanservjs    | + [ ! -z "HP Neverstop Laser MFP 1202w" = "http://printer.xxx/eSCL" ]
scanservjs    | + echo "HP Neverstop Laser MFP 1202w" = "http://printer.xxx/eSCL"
scanservjs    | + sed s/;/\n/
scanservjs    | + devices="HP Neverstop Laser MFP 1202w" = "http://printer.xxx/eSCL"
scanservjs    | + sed -i /^\[devices\]/a "HP Neverstop Laser MFP 1202w" = "http://printer.xxx/eSCL" /etc/sane.d/airscan.conf
scanservjs    |
scanservjs    | unset IFS
scanservjs    | + unset IFS
scanservjs    | set +f
scanservjs    | + set +f
scanservjs    |
scanservjs    | service dbus start <--------------
scanservjs    | + service dbus start <--------------
scanservjs    | Starting system message bus: dbus. <--------------
scanservjs    |
scanservjs    | node ./server/server.js
scanservjs    | + node ./server/server.js
scanservjs    | [2021-12-23T01:42:33.838Z] INFO (server): Started

Hopefully there's a better way to bind into dbus services inside the container? I will do some further testing and report back if I learn anything new.

Thank you!

sbs20 commented 2 years ago

Hi!

I have a feeling that dbus should not be started automatically inside the container. Are you able to build the container yourself but remove that line from run.sh?

StarkZarn commented 2 years ago

Oh my god. This is my problem. I've been chasing down this stupid "The name org.freedesktop.systemd1 was not provided by any .service files: unknown" error for so long....

Everything in my stack worked perfectly prior to this, so maybe it was an update that borked it. Removing this container fixed everything though.

Even if this doesn't get fixed, thank you @leandrotoledo for making this known.

leandrotoledo commented 2 years ago

@zemsten I know the feeling, it was driving me crazy. I even reinstalled my whole system thinking something else was borked. :-(

@sbs20 turns out my printer works with AirScan without the host dbus, so I might not be able to fully test the impact of removing it from starting on run.sh.

sbs20 commented 2 years ago

I'm removing the dbus start - I hadn't appreciated the bad side effects.

sbs20 commented 2 years ago

With any luck this is resolved now. At the very least, it won't automatically restart anything.

I'm going to mark the issue as closed for now - but do let me know if there are still problems and we can re open.