1

I am looking to have a host start up and run usbip

[Unit]
Description=USB-IP Binding
After=network-online.target

[Service]
ExecStartPre=/usr/sbin/usbipd -D
ExecStart=/usr/sbin/usbip bind --busid 1-1.5
ExecStop=/usr/sbin/usbip unbind --busid 1-1.5
Restart=on-failure  

[Install]
WantedBy=default.target

It appears to start correctly with out error, but when i go to the client and list the server it does not show that usbip running.

Also does anyone know of a script to share all USB device via USBIP.

Thank you for the help.

  • Check the process ID of the usbipd process: does it keep changing or stay the same once you've started your service? Your service might expect the usbip bind command to keep running forever, and I'm not sure that's how it actually works. Also, if you have any sort of iptables firewalling configured, have you allowed access to TCP port 3240 of the server host from the client host? – telcoM Jul 7 at 10:52
  • Thank you for the reply. I was able to find out a way to get it work, see link below. community.home-assistant.io/t/… – demslam Jul 8 at 18:32
1

Based on the link OP posted in the comments, the problem seems to have been here:

ExecStartPre=/usr/sbin/usbipd -D
ExecStart=/usr/sbin/usbip bind --busid 1-1.5

If you don't specify a Type= option for a systemd service, it assumes the service is of Type=simple. In that case, systemd will assume that the process started with the ExecStart= option will run forever if all is well. But the usbip bind command just tells the usbipd process to take over the service, and then exits. Then systemd will think "Oh no, the service has crashed!", and since it also has Restart=on-failure, it will keep restarting the service, over and over and over.

To make it work, you might specify Type=forking and make the actual usbipd process be the ExecStart= line, and usbip bind be an ExecStartPost= line, as suggested in the link you posted. But that solution has a mistake that is typical to new users of systemd: you're assuming that usbipd needs to become a daemon process on its own, while systemd can easily do it for you.

The best solution is to remove the -D option from the usbipd command line, and omit the Type=forking (or use Type=simple explicitly). This way, systemd will deal with the daemonization for you, and will also be able to monitor and stop the service process without resorting to PID files or haphazard killall usbipd ExecPost= commands.

So, what I'd recommend is:

[Unit]
Description=USB-IP Binding
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/sbin/usbipd
ExecStartPost=/usr/sbin/usbip bind --busid 1-1.5
ExecStop=/usr/sbin/usbip unbind --busid 1-1.5  

[Install]
WantedBy=multi-user.target

With these settings, systemd will expect that the usbipd process will run forever, and will in fact mark the service as failed if the process dies unexpectedly. You could add Restart=on-failure, if you want the systemd to automatically restart the service in that case.

When shutting down the service, the ExecStop command will tell usbipd to cleanly unbind from the USB device, and once that's successfully done, systemd will see that the server process is still running, and will kill it without any explicit command.

Whenever you use After=network-online.target, you should always also use Wants=network-online.target, or else it might not work as expected. See Running Services after the Network is Up in systemd documentation, which is also referred to in the man page covering the systemd special targets, systemd.special(7).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.