Search code examples
linuxreal-timeupstartjack

How to start a process with realtime priority (jackd) with upstart?


I'm trying to start jackd with realtime priority at boot with an upstart script but with no success so far. I'm using ubuntu server 14.04. My upstart version is 1.12.1.

If I start jackd without realtime the upstart script works as intended. The user and group I'm using to start jackd in the script are allowed to use realtime priority, but when upstart run it that does not seems to matter. Whenever i try to run it through upstart I get this on upstart log:

jackdmp 1.9.10
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2013 Grame.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
Cannot create thread 1 Operation not permitted
Cannot create thread 1 Operation not permitted
Cannot create thread 1 Operation not permitted
JACK server starting in realtime mode with priority 70
Cannot lock down 82274202 byte memory area (Cannot allocate memory)
Cannot create thread 1 Operation not permitted
ERROR: messagebuffer not initialized: libffado 2.1.9999- built Oct 19 2013 16:01:07
ERROR: messagebuffer not initialized: 1408466326248438: Error (PosixThread.cpp)[ 161] Start: Cannot create realtime thread (1: Operation not permitted)
ERROR: messagebuffer not initialized: 1408466326248486: Error (PosixThread.cpp)[ 162] Start:  priority: 75
firewire ERR: FFADO: Error creating virtual device
Cannot attach audio driver
JackServer::Open failed with -1
Failed to open server

If I just run the very same command that is in my exec line of the upstart script in a terminal it works fine.

My upstart script is a very simple one:

description "jackd"

start on stopped rc
stop on runlevel [06]


exec su radiola -c "jackd -R -P 70 -d firewire -r 44100 -n 3 -p 2048"

I have also tried to use the setuid and setguid stanzas and start-stop-daemon but it ended up with the same results that i just described. My file /etc/security/limits.d/audio.conf is as follows:

@audio   -  rtprio     95
@audio   -  memlock    unlimited
#@audio   -  nice      -19

The user that i'm trying to start jackd with belongs to the audio group.

Is there a way to make upstart start a realtime process? If not, is there other solution to this problem?

Thank you.


Solution

  • The /etc/security/limits.d/audio.conf file is only read when a user is opening a session (e.g. when pam_limits.so is loaded).

    You can set the same limits directly from the upstart script with the limit directive:

    limit memlock unlimited unlimited
    limit rtprio 95 95
    

    Also, in order to switch to the radiola, instead of using su, you can use the setuid/setgid directives:

    setuid radiola
    setgid audio