Autostart simple alsaloop command Topic is solved

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
Gueron
Posts: 9
Joined: Wed Apr 19, 2017 11:51 am

Autostart simple alsaloop command

Post by Gueron »

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.
Gueron
Posts: 9
Joined: Wed Apr 19, 2017 11:51 am

Re: Autostart simple alsaloop command

Post by Gueron »

Not so sure, tried again and it seemed to not time out.. I will check a few times after the weekend..
User avatar
Joulinar
Posts: 2617
Joined: Sat Nov 16, 2019 12:49 am

Re: Autostart simple alsaloop command

Post by Joulinar »

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/ ... t-startup/
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Gueron
Posts: 9
Joined: Wed Apr 19, 2017 11:51 am

Re: Autostart simple alsaloop command

Post by Gueron »

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
User avatar
Joulinar
Posts: 2617
Joined: Sat Nov 16, 2019 12:49 am

Re: Autostart simple alsaloop command

Post by Joulinar »

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

Code: Select all

ExecStart /full/path/to/alsaloop -C hw:CARD=CODEC,DEV=0 -P hw:CARD=sndrpihifiberry,DEV=0 &
pls use full patch to alsaloop
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Gueron
Posts: 9
Joined: Wed Apr 19, 2017 11:51 am

Re: Autostart simple alsaloop command

Post by Gueron »

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..
User avatar
Joulinar
Posts: 2617
Joined: Sat Nov 16, 2019 12:49 am

Re: Autostart simple alsaloop command

Post by Joulinar »

Hi,

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

Code: Select all

systemctl cat <your-name>.service
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Post Reply