Can't start a headless JACK server

I’ve dusted off some old hardware with a project in mind. My goal is to configure my old Pi 2 as a sound-card for an M-Audio Hammer 88 keyboard. I’ve been at this a couple of days now, reviewing posts and man pages and the like, and I’m afraid I finally have to ask assistance directly.

I have configured a shell script that launches:

  • a JACK server,


  • FLUID Synth with the desired options, and


  • connects the keyboard with aconnect.

However, I cannot get it to execute unless I run it through a root-privileged x session (sudo startx).

While it’s certainly possible for me to launch it once, my goal is to hand it off to a six-year-old child so that she can use it as a standalone instrument. The goal is to plug it in, flip the switch on a surge protector, and have it producing sound in under a minute.

Is it possible to automate this process with the tools I’ve described, or am I missing a critical component?

Thanks.

Just a little note about the permissions: Assure that the login user is part of the audio group: usermod -aG audio
For direct graphics and rendering access there are two other groups:
usermod -aG video
usermod -aG render

Is this a GUI application or why must it execute from an x session? And do you mean it must run from within a desktop session or can you start it directly as X application, e.g. via xinit as well?

Generally I would use a systemd service to start things automatically on boot and as early as possible boot stage, but if it must run from within desktop session, then you need to use desktop auto login and some desktop specific auto launch option.

Thank you for the rapid reply!
So, I’ve tried a couple approaches to this. The first was to use the dietpi custom.sh not option (apologies for the ambiguity, I’m away from the house at the moment), and I kept getting an X11 $DISPLAY error even though everything was command line. I believe I’ve added my root login to the audio group but I’ll double check.

It’s not a gui application. I don’t know why it needs an x session, honestly. If I start the desktop, I can run it in a terminal window with no GUI. It uses dbus as a service, which I’m not terribly familiar with, but the reading I’ve done seems to indicate it needs some flavor of display.

I’ll try to sort the dbus and systemd as soon as I get back, and provide some more complete information.
Thanks again.

Okay so first dbus needs to be installed then and probably systemd-logind unmasked (both done by default when you install a desktop through dietpi-software:

systemctl unmask systemd-logind
G_AGI dbus libpam-systemd
systemctl start systemd-logind

If starting the program from console (outside of desktop session) fails with X11 error then it is probably still possible to invoke it via xinit <program_command>.

Hmm.
So, I’ve placed the code from the last post at the beginning of my ‘/var/lib/dietpi/dietpi-autostart/custom.sh’ file and I get the message

line 3: G_AGI: command not found

I did manage to get the JACK server up and running in a logged in session by pointing the .bashrc file to another script, but then the system refused to move beyond that step. Using xinit had the same effect.
The standard cancel (^C) and suspend (^Z) keystrokes didn’t work, and I had to ssh in on another client to kill the processes.
Shoving JACK into a background process seems to allow the server to launch and lets me bring up fluidsynth, but then the audio ends up glitchy and I get the message

JackAudioDriver::ProcessGraphAsyncMaster: Process error

when I hit too many notes.

I’m fiddling with the jackd start conditions now to see if I can resolve it. I am, however, open to suggestions on optimization.

edit: It immediately occurs to me that the code previously provided was meant as a one-time execution. So, um. Thanks!