Autostart simple alsaloop command

Having successfully used a pi with hifiberry amp hat as a synthesizer for my piano, taking midi in and creating sounds with fluidsynth,
I am now trying to simply use the same hardware as an amplifier. I have added a Behringer usb sound card for stereo sound capture
from the piano audio out.

In a bash shell I can simply use : alsaloop -C hw:CARD=CODEC,DEV=0 -P hw:CARD=sndrpihifiberry,DEV=0 &
which works fine.

If I put this into rc.local to run headless from boot, it needs a wait for usb to set-up, but even with an initial sleep I could not get this
to work.

I tried to use the option of the autostart script, with this command placed in /var/lib/dietpi/dietpi-autostart/. This starts and runs but stops
after some time (a few minutes) even if I add RuntimeMaxSec=infinity to the service (after some googling).

But if I simply order a reboot via shell, not only does it restart but never times out ??? How come ? I am on the v6.30 dietpi version.

Not so sure, tried again and it seemed to not time out… I will check a few times after the weekend…

Hi,

as well you can create your own service file. I will link a small guide describing a couple of ways to run you stuff at startup. The service method is described on point 4: SYSTEMD

https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/

Have checked and still does not work for me.
I have tried various changes in the system service autostart, type, idle, simple, forking, infinite time, always restart…
but to no avail, After under 5 mins the command stops, but if I reboot it keeps active much longer.
My service is:
[Unit]
Description=DietPi-Autostart (Custom /var/lib/dietpi/dietpi-autostart/custom.sh)
Requisite=dietpi-boot.service
After=dietpi-boot.service dietpi-postboot.service rc-local.service
ConditionPathExists=/var/lib/dietpi/dietpi-autostart/custom.sh

[Service]
Type=simple
RemainAfterExit=yes
StandardOutput=tty
ExecStartPre=/bin/chmod +x /var/lib/dietpi/dietpi-autostart/custom.sh
ExecStartPre=/bin/echo ‘Starting DietPi-Autostart (Custom) script…’
ExecStart=/var/lib/dietpi/dietpi-autostart/custom.sh
RuntimeMaxSec=infinity
Restart=always

[Install]
WantedBy=multi-user.target

and the custom.sh is simply :
#!/bin/bash
alsaloop -C hw:CARD=CODEC,DEV=0 -P hw:CARD=sndrpihifiberry,DEV=0 &
exit 0

I would appreciate comments on what is wrong… thanks

no need to call custom.sh with your own service.You could call the command directly

ExecStart /full/path/to/alsaloop -C hw:CARD=CODEC,DEV=0 -P hw:CARD=sndrpihifiberry,DEV=0 &

pls use full patch to alsaloop

Thanks very much, that works !

I initially left my simple command in a separate script file to remain compatible with the autostart option during
dietpi-config in a clean install, which I felt would be easier to maintain.

So summary,

anyone who wants a single line command at start-up, and which remains always active,
better use this solution than a separate script file…

Hi,

would it be possible to post your service file. Maybe it could help others

systemctl cat <your-name>.service