Installation of saned with systemd (no inetd or xinetd) - saned refuses connection

6,594

Solution 1

Proper systemd cooperation is in SANE 1.0.25, SANE 1.0.24 has issues remaining. More on SANE bug tracker. To get saned working with systemd, one should either use the sane-utils 1.0.25 version (not in Raspbian Jessie) or make adjustments to the 1.0.24 version.

In short, libsystemd-dev needs to be installed for the systemd glue to work, and the saned.service edited to match the man page suggestion for 1.0.25: 1.0.25 man page.

Man Page for 1.0.25

Systemd configuration when saned is compiled without systemd support

This configuration will also work when Saned is compiled WITH systemd integration support, but it does not allow debugging information to be logged.

saned.socket (unchanged)

[Unit]
Description=saned incoming socket

[Socket]
ListenStream=6566
Accept=yes
MaxConnections=1

[Install]
WantedBy=sockets.target

[email protected] (changed, works also if systemd support is compiled in, but doesn't allow logging of debugging information)

[Unit]
Description=Scanner Service
Requires=saned.socket

[Service]
ExecStart=/usr/sbin/saned
User=saned
Group=saned
StandardInput=socket

Environment=SANE_CONFIG_DIR=/etc/sane.d

[Install]
Also=saned.socket

You can also enter Alias=saned.service in the last install stanza after Also=saned.socket to have both saned references start with the same saned.*

Also, /etc/default/saned needs to contain RUN=no or the service fails, and as a reminder, the saned server address or FQDN (not just the server name) needs to be put in /etc/sane.d/net.conf on all client machines.

Solution 2

But when I try to telnet into the open port on the pi, the connection is refused:

pi@EMK-RPiBv1:~$ telnet localhost 6566
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

But, um, it's not refused. If it was, you would see "Connection refused". But it clearly says "Connected" here – the connection was accepted, and then closed by the actual service.

Anyway: I can guess at two problems:

  1. With inetd-like socket activation such as this, the saned service isn't running until a connection is attempted. Therefore it cannot appear in scan results either (since it's not running during the scan). So instead you might need to run it as a permanent service, not a socket-activated one.

  2. Your saned.service is not a real systemd service; it was automatically converted from /etc/init.d/saned (as the "LSB:" prefix shows). As the init.d conversion needs to handle many weird edge cases, sometimes it results in services that are barely working – especially when combined with socket activation. Thus you should avoid starting saned's native-systemd units and LSB-converted units at the same time.

Share:
6,594

Related videos on Youtube

emk2203
Author by

emk2203

Updated on September 18, 2022

Comments

  • emk2203
    emk2203 over 1 year

    I have set up a Raspberry Pi B v1 with a minimal Jessie image and configured it for printing via cups and scanning via saned.

    The local setup is without issues; a

    pi@EMK-RPiBv1:~$ scanimage -L device 'fujitsu:ScanSnap S1500:25959' is a FUJITSU ScanSnap S1500 scanner

    However, the scanner is not visible on the network. a scanimage -L on another machine shows emk2203@XPS12-9Q33:~$ scanimage -L device 'hpaio:/net/HP_LaserJet_CM1415fn?ip=192.168.1.30' is a Hewlett-Packard HP_LaserJet_CM1415fn all-in-one device 'hpaio:/net/HP_Officejet_Pro_276dw_MFP?ip=192.168.1.40' is a Hewlett-Packard HP_Officejet_Pro_276dw_MFP all-in-one

    So, the scanimage -L works - it finds the two other networked scanners, but not the scanner attached to the Raspi.

    If I issue netstat -tulpn on the pi and check the status of saned.service and saned.socket, I get

    pi@EMK-RPiBv1:~$ netstat -tulpn
    (Not all processes could be identified, non-owned process info
    will not be shown, you would have to be root to see it all.)
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:631             0.0.0.0:*               LISTEN      -               
    tcp6       0      0 :::6566                 :::*                    LISTEN      -               
    tcp6       0      0 :::22                   :::*                    LISTEN                    
    tcp6       0      0 :::631                  :::*                    LISTEN      
    udp        0      0 0.0.0.0:42976           0.0.0.0:*                           
    udp        0      0 0.0.0.0:5353            0.0.0.0:*                           
    udp        0      0 0.0.0.0:29987           0.0.0.0:*                           
    udp        0      0 0.0.0.0:68              0.0.0.0:*                           
    udp        0      0 192.168.1.34:123        0.0.0.0:*    -                       
    udp        0      0 127.0.0.1:123           0.0.0.0:*-                           
    udp        0      0 0.0.0.0:123             0.0.0.0:*-                           
    udp6       0      0 :::35810                :::*     -                           
    udp6       0      0 :::5353                 :::*     -                           
    udp6       0      0 :::49009                :::*     -                         
    udp6       0      0 fe80::ba27:ebff:fe4:123 :::*     -                          
    udp6       0      0 2a02:8070:a182:ce00:123 :::*     -                           
    udp6       0      0 ::1:123                 :::*     -                           
    udp6       0      0 :::123                  :::*     -                        
    
    pi@EMK-RPiBv1:~$ systemctl status saned.socket
    ● saned.socket - saned incoming socket
        Loaded: loaded (/lib/systemd/system/saned.socket; enabled)
        Active: active (listening) since Sun 2015-10-11 20:01:52 CEST; 2min 18s ago
        Listen: [::]:6566 (Stream)
    Accepted: 0; Connected: 0
    
    pi@EMK-RPiBv1:~$ systemctl status saned.service
    ● saned.service - LSB: SANE network scanner server
       Loaded: loaded (/etc/init.d/saned)
       Active: active (exited) since Sun 2015-10-11 20:01:53 CEST; 2min 26s ago
      Process: 342 ExecStart=/etc/init.d/saned start (code=exited, status=0/SUCCESS)
    

    The open port is shown for tcp6 only, but according to pi@EMK-RPiBv1:~$ sudo sysctl net.ipv6.bindv6only I get net.ipv6.bindv6only = 0 - this shouldn't be a problem, since ipv6 is not bound to only v6, but includes ipv4 as well.

    But when I try to telnet into the open port on the pi, the connection is refused:

    pi@EMK-RPiBv1:~$ telnet localhost 6566
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    Connection closed by foreign host.
    

    This indicates that I can't reach my saned.

    If I kill the systemd service and socket for saned and try to debug, I get the following:

    root@EMK-RPiBv1:~# systemctl stop saned.service
    root@EMK-RPiBv1:~# systemctl stop saned.socket
    root@EMK-RPiBv1:~# lsof -i :6566
    

    So, nothing listening at the moment - no output.

    root@EMK-RPiBv1:~# saned -d128 -a saned
    [saned] main: starting debug mode (level 128)
    [saned] read_config: searching for config file
    [saned] read_config: done reading config
    [saned] saned (AF-indep+IPv6) from sane-backends 1.0.24 starting up
    [saned] do_bindings: trying to get port for service "sane-port"   (getaddrinfo)
    [saned] do_bindings: [1] socket () using IPv6
    [saned] do_bindings: [1] setsockopt ()
    [saned] do_bindings: [1] bind () to port 6566
    [saned] do_bindings: [1] listen ()
    [saned] do_bindings: [0] socket () using IPv4
    [saned] do_bindings: [0] setsockopt ()
    [saned] do_bindings: [0] bind () to port 6566
    [saned] do_bindings: [0] bind failed: Address already in use
    [saned] run_standalone: spawning Avahi process
    [saned] run_standalone: waiting for control connection
    [saned] saned_avahi_callback: AVAHI_CLIENT_S_RUNNING
    [saned] saned_create_avahi_services: adding service 'saned'
    [saned] saned_avahi_group_callback: service 'saned' successfully established
    

    What do I need to do to open the connection? Without installing inetd or xinetd, please. This should work with systemd alone.

  • emk2203
    emk2203 over 8 years
    Your observation of telnet behaviour, coupled with 2., was right on the mark and helped me pinpoint the issue. Proper systemd cooperation is in SANE 1.0.25, SANE 1.0.24 has issues remaining. More on SANE bug tracker. In short, libsystemd-dev needs to be installed for the systemd glue to work, and the saned.service edited to match the man page suggestion for 1.0.25: 1.0.25 man page. Also, /etc/default/saned needs to contain RUN=no or the service fails.
  • emk2203
    emk2203 over 8 years
    What stays the same is that the SANE server address or FQDN has to be explicitly in the /etc/sane.d/net.conf on the client.