You are not logged in.

#1 2012-11-23 21:27:47

bicyclingrevolution
Member
Registered: 2010-10-18
Posts: 65

How can I start Jack with systemd?

Hello everyone,

I switched to systemd and removed initscripts and sysvinit a while ago. I am using my computers for audio production, and I need both jack and pulseaudio.
I followed the directions in the wiki for JACK: A GUI-Based Setup and Pulseaudio will run through Jack -- as long as Jack starts first. Qjackctl is autostarted with KDE, but Pulseaudio starts up first. Therefore, once Jack starts, it disconnects Pulseaudio so only Jack programs output audio. The wiki recommends adding "sudo -u uname jack_start" to /etc/rc.local. However, I have already switched away from initscripts.

I tried to write a service file to start Jack:

[Unit]
Description=JACK

[Service]
ExecStart=/usr/bin/jack_control start

[Install]
WantedBy=multi-user.target

But that clearly didn't work:

Nov 23 12:01:58 silverstone jack_control[280]: Traceback (most recent call last):
Nov 23 12:01:58 silverstone jack_control[280]: File "/usr/bin/jack_control", line 336, in <module>
Nov 23 12:01:58 silverstone jack_control[280]: main()
Nov 23 12:01:58 silverstone jack_control[280]: File "/usr/bin/jack_control", line 132, in main
Nov 23 12:01:58 silverstone jack_control[280]: bus = dbus.SessionBus()
Nov 23 12:01:58 silverstone jack_control[280]: File "/usr/lib/python2.7/site-packages/dbus/_dbus.py", line 211, in __new__
Nov 23 12:01:58 silverstone jack_control[280]: mainloop=mainloop)
Nov 23 12:01:58 silverstone jack_control[280]: File "/usr/lib/python2.7/site-packages/dbus/_dbus.py", line 100, in __new__
Nov 23 12:01:58 silverstone jack_control[280]: bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
Nov 23 12:01:58 silverstone jack_control[280]: File "/usr/lib/python2.7/site-packages/dbus/bus.py", line 122, in __new__
Nov 23 12:01:58 silverstone jack_control[280]: bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
Nov 23 12:01:58 silverstone jack_control[280]: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Nov 23 12:01:58 silverstone systemd[1]: jack.service: main process exited, code=exited, status=1/FAILURE
Nov 23 12:01:58 silverstone systemd[1]: Unit jack.service entered failed state
Nov 23 12:02:00 silverstone pulseaudio[337]: [pulseaudio] module-jack-sink.c: JACK error >Cannot connect to server socket err = No such file or directory<
Nov 23 12:02:00 silverstone pulseaudio[337]: [pulseaudio] module-jack-sink.c: JACK error >Cannot connect to server socket<
Nov 23 12:02:01 silverstone pulseaudio[337]: [pulseaudio] module-jack-sink.c: JACK error >Cannot use real-time scheduling (RR/5)(1: Operation not permitted)<
Nov 23 12:02:01 silverstone pulseaudio[337]: [pulseaudio] module-jack-sink.c: JACK error >JackClient::AcquireSelfRealTime error<
Nov 23 12:02:01 silverstone pulseaudio[337]: [pulseaudio] module-jack-source.c: JACK error >Cannot use real-time scheduling (RR/5)(1: Operation not permitted)<
Nov 23 12:02:01 silverstone pulseaudio[337]: [pulseaudio] module-jack-source.c: JACK error >JackClient::AcquireSelfRealTime error<
Nov 23 12:02:01 silverstone pulseaudio[337]: [pulseaudio] main.c: Source jack_in  does not exist.

Can anyone help me write a service file to start Jack?

Thanks,
Nicholas

Offline

#2 2012-11-23 23:15:02

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,838

Re: How can I start Jack with systemd?

Big clue right there:

Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

Offline

#3 2012-11-24 06:31:53

bicyclingrevolution
Member
Registered: 2010-10-18
Posts: 65

Re: How can I start Jack with systemd?

Thanks for the hint tomk! From what I can understand systemd was starting Jack as root, but since Jack is pretty much a single-user program, it needs to be started by the user intending to use it. So it was throwing errors because I have no display set for root (I don't even know how to do that).
This explains why the wiki used sudo to start Jack. So I changed the service file to:

[Unit]
Description=JACK

[Service]
ExecStart=/usr/bin/sudo -u lion /usr/bin/jack_control start

[Install]
WantedBy=multi-user.target

lion is my username. There is no jack_start, I have to use jack_control start.
And it gives me:

Nov 23 22:21:35 silverstone sudo[289]: root : TTY=unknown ; PWD=/ ; USER=lion ; COMMAND=/usr/bin/jack_control start
Nov 23 22:21:36 silverstone sudo[289]: File "/usr/bin/jack_control", line 336, in <module>
Nov 23 22:21:36 silverstone sudo[289]: File "/usr/bin/jack_control", line 132, in main
Nov 23 22:21:36 silverstone systemd[1]: jack.service: main process exited, code=exited, status=1/FAILURE
Nov 23 22:21:36 silverstone systemd[1]: Unit jack.service entered failed state
Nov 23 22:21:38 silverstone pulseaudio[353]: [pulseaudio] module-jack-sink.c: JACK error >Cannot connect to server socket err = No such file or directory<
Nov 23 22:21:38 silverstone pulseaudio[353]: [pulseaudio] module-jack-sink.c: JACK error >Cannot connect to server socket<
Nov 23 22:21:39 silverstone pulseaudio[353]: [pulseaudio] module-jack-sink.c: JACK error >Cannot use real-time scheduling (RR/5)(1: Operation not permitted)<
Nov 23 22:21:39 silverstone pulseaudio[353]: [pulseaudio] module-jack-sink.c: JACK error >JackClient::AcquireSelfRealTime error<
Nov 23 22:21:39 silverstone pulseaudio[353]: [pulseaudio] module-jack-source.c: JACK error >Cannot use real-time scheduling (RR/5)(1: Operation not permitted)<
Nov 23 22:21:39 silverstone pulseaudio[353]: [pulseaudio] module-jack-source.c: JACK error >JackClient::AcquireSelfRealTime error<
Nov 23 22:21:39 silverstone pulseaudio[353]: [pulseaudio] main.c: Source jack_in  does not exist.

However, the audio setup seems to be working fine. The only other idea I have is that Jack is becoming a dbus socket and makes systemd think it failed. But Pulseaudio is also claiming that it can't connect to jack., so I don't know whether it's working or not.
I saw a way to set up a .service file for dbus sockets but it required the dbus name of the program, which I don't know how to find.

Offline

#4 2012-12-01 20:47:44

clovenhoof
Member
From: Bulgaria
Registered: 2010-09-16
Posts: 82

Re: How can I start Jack with systemd?

Did you find any solution about starting jack with systemd?

Last edited by clovenhoof (2012-12-01 20:48:11)

Offline

#5 2012-12-02 22:48:58

bicyclingrevolution
Member
Registered: 2010-10-18
Posts: 65

Re: How can I start Jack with systemd?

Hi clovenhoof,

I can't tell whether the service file I posted above actually works or not. The errors seem to say it doesn't work, but when I boot into the desktop jack is already running before qjackctl. The setup seems to work.
However, I am having a problem with Pulseaudio almost every time I resume from standby or hibernate. Jack is running but Pulseaudio forgot the Jack output, falling back to Null. I have to run

pulseaudio -k
pulseaudio & 

and then use pavu to reroute any programs (only Amarok so far actually) from Null to Jack sink. This happens on my desktop and laptop and is extremely annoying. Actually I don't have the jack.service on my laptop and now that I rebooted nothing is working . . . . . . . .

Offline

#6 2012-12-03 11:25:44

clovenhoof
Member
From: Bulgaria
Registered: 2010-09-16
Posts: 82

Re: How can I start Jack with systemd?

I have just moved to systemd and I'll going to find a solution to construct jack.service.
I think we should use this: https://wiki.archlinux.org/index.php/JA … ection_Kit
as starting point. This section [Jack for a multi-user system] describes how to use jack as system wide daemon.

I'm going to try it and then post results here.

PP: In my case I use headless archlinux media server running only mpd on it. I don't use pulseaudio, just jack -> alsa.

Last edited by clovenhoof (2012-12-03 11:26:34)

Offline

#7 2012-12-04 12:53:30

clovenhoof
Member
From: Bulgaria
Registered: 2010-09-16
Posts: 82

Re: How can I start Jack with systemd?

Ok. It works now. Here how I made it.

The problem was dbus enabled version of jack, so I installed from AUR  jack2-git.
Then I create the following jack.service file:

[Unit]
Description=JACK
After=sound.target

[Service]
User=stefan
ExecStart=/usr/bin/jackd -R -P 20 -d alsa -P hw:0,1 -r 96000 -p 64 -n 2

[Install]
WantedBy=multi-user.target


BTW: It works like that, but do I need to use "Type=forking" or not?

Last edited by clovenhoof (2012-12-04 12:53:41)

Offline

Board footer

Powered by FluxBB