Configure Ecasound as a Persistent Systemd Service

This guide explains how to set up, configure, and manage Ecasound as an automated, persistent background service using systemd. By running Ecasound under systemd, you ensure that your audio routing, processing, or recording chains start automatically upon boot, restart cleanly after hardware or software failures, and operate smoothly without requiring an interactive terminal session.

1. Configure Ecasound for Non-Interactive Execution

Ecasound defaults to an interactive terminal interface when launched. When managed by systemd, interactive input is unavailable, which causes standard Ecasound processes to terminate immediately. To prevent this, you must run Ecasound with flags that suppress interactive mode.

Key options to include in your command:

A typical headless routing command:

ecasound -K -i:alsahw,1,0 -o:alsahw,0,0

2. Determine Service Scope: User vs. System

For most dedicated appliance and direct-ALSA setups, a system-level unit is standard. For desktop sessions or PipeWire/PulseAudio integrations, create a user unit.

3. Create the Systemd Unit File

For a system-wide service, create /etc/systemd/system/ecasound.service. For a user-level service, create ~/.config/systemd/user/ecasound.service.

Add the following configuration:

[Unit]
Description=Ecasound Audio Processing Engine
After=sound.target
Wants=sound.target

[Service]
Type=simple
# Ensure the user belongs to the 'audio' group if running as a dedicated user
User=audio-user
Group=audio
# Environment variables can be defined here if ALSA or JACK paths are needed
Environment=ALSA_CARD=Generic

# Replace the ExecStart line with your specific Ecasound chain setup
ExecStart=/usr/bin/ecasound -K -q -i:alsahw,1,0 -o:alsahw,0,0

Restart=always
RestartSec=3

# Resource limits to prevent lockups during buffer underruns
LimitRTPRIO=95
LimitMEMLOCK=infinity

[Install]
WantedBy=multi-user.target

If configuring as a user service:

  1. Remove the User= and Group= directives (the current user owns the process).
  2. Change WantedBy=multi-user.target to WantedBy=default.target.

4. Enable Persistent Execution (For User Services Only)

If running Ecasound as a user service on a headless machine, systemd will terminate the process whenever the user logs out. Enable systemd lingering to allow the user service to start at boot and persist continuously:

loginctl enable-linger audio-user

5. Enable and Start the Service

Reload the systemd manager configuration to recognize the new unit file:

For system services:

sudo systemctl daemon-reload
sudo systemctl enable --now ecasound.service

For user services:

systemctl --user daemon-reload
systemctl --user enable --now ecasound.service

6. Verify Operation and Monitor Logs

Check the status of the process:

systemctl status ecasound.service

To monitor real-time output and debug audio chain errors or ALSA device conflicts:

journalctl -u ecasound.service -f