SimulPiscator / AirSane

Publish SANE scanners to MacOS, Android, and Windows via Apple AirScan.
GNU General Public License v3.0
247 stars 26 forks source link

Delay Service Start on Boot #33

Closed hftsai256 closed 4 years ago

hftsai256 commented 4 years ago

I've noticed that the service may fail with the following error on boot:

Jul 29 15:26:11 nanopi airsaned[1240]: [bjnp] create_broadcast_socket: ERROR - bind socket to local address failed - Cannot assign requested address
Jul 29 15:26:17 nanopi airsaned[1240]: server finished with error status -1, last error was 99: Cannot assign requested address

I'm not an expert in networking services loading order but one hacky way to get around it could be delay the service by a couple of seconds e.g.:

[Service]
ExecStartPre=/bin/sleep 10
SimulPiscator commented 4 years ago

The error message refers to the bjnp backend, I'm not sure whether AirSane can do anything about it. If the delay fixes it, it's fine.

hftsai256 commented 4 years ago

I did a closer look on this and turns out they are two separate issues.

The first one is when airsaned starts after the network interface is up, but before it is actually online. I found this reference and change After=network.target to After=network-online.target which can then bring up airsaned on boot successfully.

The second one still remains after the first fix, but turns out it doesn't have impact on the actual functionality.

Thanks.

SimulPiscator commented 4 years ago

This is very helpful, thank you. I modified the systemd service description accordingly.

hiatsu0 commented 3 years ago

My /lib/systemd/system/airsaned.service already had After=network-online.target in it by default but still I had to add the ExecStartPre=/bin/sleep 15 before I could have the service start successfully on boot (on Raspberry Pi 3). More info in the issue I wrote (https://github.com/SimulPiscator/AirSane/issues/55) before finding this one.

[Unit]
Description=AirSane Imaging Service
After=network-online.target

[Service]
EnvironmentFile=-/etc/default/airsane
ExecStartPre=/bin/sleep 15
ExecStart=/usr/local/bin/airsaned --interface=${INTERFACE} --base-port=${BASE_PORT} --access-log=${ACCESS_LOG} --hotplug=${HOTPLUG} --mdns-announce=${M$
ExecReload=/bin/kill -HUP $MAINPID
User=saned
Group=saned
Type=simple

[Install]
WantedBy=multi-user.target
Alias=airsaned.service