1

We have an application "my-app" that is autostarted by xdg (.config/autostart/my-app.desktop). We need sound through the hdmi sound device. This is not the default device after a fresh installation. So we need to fix this, before my-app autostarts, or it will not detect the correct device.

Setting the device with wpctl set-default ID works, but my-app does not detect this because it is already running. We can not alter my-app or how it starts.

I considered also autostarting a script to set the correct device, but xdg does not support ordering among the autostarted programs, so no guarantee that this will be done before my-app.

I see that the .config/autostart/my-app.desktop file results in an autogenerated systemd user service app-my\[email protected]. I tried making a new user service /etc/systemd/user/set-default-audio.service to do the audio config, and juggling the systemd dependency statements so that it has to run before the autogenerated one, but without success - I can not get it to run on login. Should it be possible to do it this way?

I have considered doing the audio configuration at boot rather than login, but the problem is that all the pipewire stuff seems to be starting as --user systemd services, and hence none of it is running before we log in.

Is there a different way to automatically make our audio configured properly before our my-app autostarts? This must be working on first login after our automatic installation has run.

We're running RHEL9.2.

6
  • 1
    "Should it be possible to do it this way?" yes! That's what I'd have recommended, and how I start some of the things I need on my sessions. Commented Dec 1 at 17:11
  • 1
    Note that having /etc/systemd/user/set-default-audio.service does not automatically make it start. It needs to be pulled (e.g. wanted by default.target and enabled). Commented Dec 1 at 22:27
  • @TomYan Yes, this is what I was trying to achieve by "juggling the systemd dependency statements" - but without success so far. Which WantedBy (or other statements) would be needed to make it run after pipewire is up but before the my-app automatic service? I had tried WantedBy=xdg-desktop-autostart.target and WantedBy=app-my\[email protected], as well as Requires=wireplumber.service Commented Dec 2 at 8:50
  • You don't really need a specific WantedBy=, but basically just anything that has also been "enabled", and as I said default.target would be a good candidate. after pipewire So obviously you also need After=wireplumber.service. (You don't need Requires=wireplumber.service as long as you have that and pipewire.service enabled.) Also check whether you actually can not get it to run on login or if the command failed for reasons. Commented Dec 2 at 9:16
  • Make sure to disable the service before changing the [Install] section, and systemctl --user daemon-reload and re-enable it afterwards. Commented Dec 2 at 9:20

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.