Routing pisound's input to output with the start of jack service

Hey!

Trying to figure out a rather “non-destructive” way to automatically route the input to output of pisound when jack.service is starting. Tried ExecPost …but this is not working (…which makes sense). I read a lot about meta services etc. but this is all kind of confusing - what is the correct way of launching my

Jack_connect.sh
#!/bin/bash
/usr/local/bin/jack_connect system:capture_2 system:playback_2 ; /usr/local/bin/jack_connect system:capture_1 system:playback_1

script (or the commands inside of it)?

Any help is much appreciated!

1 Like

Hi, you could create your own .service file that would run after jack.service gets started (using After=jack.service). Make sure that you have EnvironmentFile=/etc/environment in your .service. (check pisound-btn.service as an example). This is so that the service imports the environment variables necessary to access the shared Jack backend.

Make sure that /usr/local/bin/jack_connect is the right path, the ‘local’ is usually used for software compiled locally, but jack is installed as a .deb package on Patchbox OS image, so normally the path should be /usr/bin/jack_connect. (however, I don’t have access to RPi atm, so can’t double check)

It may be useful in your script to call jack_wait first, this command should wait until Jack backend is fully started.

Also make sure that ‘chmod +x’ has been done on your script. :slight_smile:

2 Likes

Hey @Giedrius!

Thanks for the really useful tipps!

It works!

jackc.service
[Unit]
Description=Jack Connect daemon autostart
After=jack.service

[Service]
EnvironmentFile=/etc/environment
User=jack
Group=jack
ExecStart=/home/patch/Jack_connect.sh
CPUSchedulingPriority=95
CPUSchedulingPolicy=rr
MemoryLimit=512M
MemorySoftLimit=512M
LimitRTPRIO=infinity
LimitRTTIME=infinity
LimitMEMLOCK=infinity

[Install]
WantedBy=jack.service

I had to add those Scheduling / RT additions to avoid Buffering Allocation errors - but this seems to do the job.

The Jack_connect.sh looks like this:

#!/bin/bash

/usr/bin/jack_wait -w ; /usr/bin/jack_connect system:capture_2 system:playback_2 ; /usr/bin/jack_connect system:capture_1 system:playback_1

And then I edited the /etc/systemd/system/multi-user.target.wants/jack.service - I added Wants=jackc.service

jack.service
[Unit]
Description=JACK Server
After=sound.target
Wants=jackc.service

[Service]
LimitRTPRIO=infinity
LimitMEMLOCK=infinity
Environment=JACK_NO_AUDIO_RESERVATION=1
Environment=JACK_PROMISCUOUS_SERVER=jack
ExecStart=/etc/jackdrc
User=jack
Group=jack


[Install]
WantedBy=multi-user.target

Edit: Found the solution and edited post accordingly - maybe I didn’t do it all correctly - I am open for suggestion how to improve this

1 Like

I think you don’t need to edit this by hand, just create your .service in /usr/lib/systemd/system, then run: (assuming you named your file jackc.service)

sudo systemctl daemon-reload # This picks up the changes in .service files
sudo systemctl start jackc.service # This runs the service immediately
sudo systemctl enable jackc.service # This enables running on boot

without this …it didn’t work with sudo systemctl restart jack (or rather stop and then start in my case) but only at startup

You should be able to use PartOf=jack.service: https://stackoverflow.com/questions/36043964/how-to-restart-a-service-if-its-dependent-service-is-restarted

I tried this but it didn’t do the job - iirc I tried the PartOf=jack.service in the jackc.service before adding Wants=jackc.service. Anyways …this works - won’t touch this anymore if that is the only thing that comes to your mind when looking at this solution.