Next revision | Previous revision |
lwc:programming:bash:systemd [2020/11/26 22:26] – created John Harrison | lwc:programming:bash:systemd [2023/10/06 15:03] (current) – John Harrison |
---|
===== Creating a systemd service ===== | ===== Creating a systemd service ===== |
| |
- create the config (?) for the service as /lib/systemd/system/<unit name>.service | * create the config (?) for the service as ''/lib/systemd/system/<unit name>.service'' |
- Inside the config: | * is it actually supposed to go in ''/etc/systemd/system'' not ''/lib/systemd/system''? |
- enable the service: sudo systemctl enable application.service | * 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]'' add ''StartLimitIntervalSec=0'' so systemd will continue to try to restart the service forever |
| * in ''[Service]'' add ''RestartSec=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'' or ''usbreset'' 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: |
| <code> |
| ACTION=="add", ATTR{idVendor}=="0582", ATTR{idProduct}=="01d6", TAG+="systemd", ENV{SYSTEMD_WANTS}="jackd.service" |
| </code> |
| //[[https://blog.nostatic.org/2020/08/starting-jack-automatically-when-usb.html|source]]// |
| |
| ==== 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 like ''After=dev-bus-usb-001-001.device dev-bus-usb-002-001.device'' |
| //[[https://superuser.com/questions/1322777/in-systemd-service-file-how-do-i-say-after-usb-is-ready|source]]// |
| |
===== References ===== | ===== References ===== |