Creating a systemd service
- create the config (?) for the service as
/lib/systemd/system/<unit name>.service
- is it actually supposed to go in
/etc/systemd/system
not/lib/systemd/system
?
- Inside the config:
- enable the service:
sudo systemctl enable application.service
Make the service restart always
Restart Always
in service has limits. Kill 'em limits:
- in
[unit]
addStartLimitIntervalSec=0
so systemd will continue to try to restart the service forever - in
[Service]
addRestartSec=1
to have systemd retry every second (instead of the default every 100ms)
Make a service start after a USB connection
- plug in the usb device look up the vender id and product id of the USB device.
lsusb
orusbreset
will both give you this information - create a file in
/etc/udev/rules.d
for example/etc/udev/rules.d/80-local.rules
and put in it something like this example:
ACTION=="add", ATTR{idVendor}=="0582", ATTR{idProduct}=="01d6", TAG+="systemd", ENV{SYSTEMD_WANTS}="jackd.service"
Make a service start after USB device initializes on bootup
Example
- create
/etc/udev/rules.d/20-usb-bus.rules
with content:KERNEL=="usb[1-2]", TAG+="systemd"
- reboot or udev rules reload and now voila:
systemctl status dev-bus-usb-001-001.device
- then in
[Unit]
you can do something likeAfter=dev-bus-usb-001-001.device dev-bus-usb-002-001.device
References
- https://wiki.archlinux.org/index.php/systemd#Handling_dependencies