how to avoid computer suspension while using jack capture?

What other apps and distros do you use to round out your studio?

Moderators: MattKingUSA, khz

wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

how to avoid computer suspension while using jack capture?

Post by wolftune »

I always have to manually switch off my power management so the computer doesn't suspend while recording with jack_capture. Is there a way to run it so that it will keep the computer from suspending?
Aaron Wolf
Music teacher, scholar
http://wolftune.com
User avatar
thetotalchaos
Established Member
Posts: 211
Joined: Mon Sep 29, 2014 8:29 pm
Has thanked: 55 times
Been thanked: 9 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by thetotalchaos »

yes! Install caffeine :)
You can listen to my music at: https://totalchaos-music.bandcamp.com/

Take a journey to wonderland with The Butterfly Effect 2016
https://totalchaos-music.bandcamp.com/a ... fly-effect
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

I should have known to try that. I used it for years, but then development halted and it stopped working well for me at one point in the last few years. But I see caffeine is back in the normal repos and updated and such! Yay! I'll give it a go, thanks!
Aaron Wolf
Music teacher, scholar
http://wolftune.com
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

update: I see caffeine now has a `caffeinate` command to add to any command-line item to engage caffeine while that command is running. However, I get this error with it:

Code: Select all

/usr/bin/caffeine-screensaver: 599: /usr/bin/caffeine-screensaver: dcop: not found
could not inhibit desktop idleness
I'm using KDE Neon. No idea why this is happening.
Aaron Wolf
Music teacher, scholar
http://wolftune.com
tramp
Established Member
Posts: 2347
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 466 times

Re: how to avoid computer suspension while using jack capture?

Post by tramp »

I don't know if this will work on KDE, as I didn't use KDE nor do know much about it internals. But, usually you could simple write a hook for pm-utils in /etc/pm/sleep.d/

so, to avoid suspend/hibernate when recording, this little script should do the trick.

Code: Select all

#!/bin/sh
# Prevents the machine from suspending or hibernating when
# jack_capture is running
case "$1" in
  suspend|hibernate)
    if pidof "jack_capture" 
    then
      exit 1;
    fi
esac
copy it as '000_prevent_suspend_hibernate' to /etc/pm/sleep.d/ and make it executable
(as root)

Code: Select all

chmod +x '/etc/pm/sleep.d/000_prevent_suspend_hibernate'
now, when jack_capture is running, suspend will be disabled.
You could simply add all the apps you wont to never suspend (ardour, audacity, . . .)
On the road again.
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

fascinating. That stuff you just put seems to replace the functionality of caffeine that was stripped out long ago.

The issue I had was with specifically the `caffeinate` operation of the `caffeine` program.

I'll try what you wrote, but I kinda think that should actually be written into some program or script that people can actually install and set to auto-start rather than just be a funny root hack I have to do. Caffeine literally had this exact list-of-programs way of working in the past, I don't know why it was removed.
Aaron Wolf
Music teacher, scholar
http://wolftune.com
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

tramp wrote:I don't know if this will work on KDE, as I didn't use KDE nor do know much about it internals. But, usually you could simple write a hook for pm-utils in /etc/pm/sleep.d/
Well, I do know that won't work because that's not how sleep is handled with systemd. The new location is /lib/systemd/system-sleep/ and the line hibernate|suspend) needs to change to pre)

I need to figure out (or get help determining) if anything else in your script needs to change.
Aaron Wolf
Music teacher, scholar
http://wolftune.com
tramp
Established Member
Posts: 2347
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 466 times

Re: how to avoid computer suspension while using jack capture?

Post by tramp »

Well, this script didn't work with systemd.
For systemd, you could run jack_capture with systemd-inhibit to avoid suspend/hibernate

Code: Select all

systemd-inhibit jack_capture
man systemd-inhibit wrote:systemd-inhibit may be used to execute a program with a shutdown, sleep, or idle inhibitor lock taken. The lock will be
acquired before the specified command line is executed and released afterwards.

Inhibitor locks may be used to block or delay system sleep and shutdown requests from the user, as well as automatic idle
handling of the OS. This is useful to avoid system suspends while an optical disc is being recorded, or similar operations
that should not be interrupted.
On the road again.
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

oh, great! systemd-inhibit sounds like a working version of the supposed `caffeinate` function from caffeine

THANKS! :D
Aaron Wolf
Music teacher, scholar
http://wolftune.com
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

darn, it didn't work! I used systemd-inhibit and my laptop still suspended! :?
Aaron Wolf
Music teacher, scholar
http://wolftune.com
tramp
Established Member
Posts: 2347
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 466 times

Re: how to avoid computer suspension while using jack capture?

Post by tramp »

It's a privilege problem, seems the suspend call comes with root privileges. In order to make it work, you need to set up the systemd-inhibit call with root privileges. To allow that without given password, you could edit /etc/sudors, or even better create a file in /etc/sudors.d/
Therefore open a terminal as root, and run

Code: Select all

visudo -f /etc/sudoers.d/myOverrides
That create a file in /etc/sudors.d/ called myOverrides.
The usual visudo editor is nano, so it looks like a blank terminal window. Just wrote in there

Code: Select all

YourUserName  ALL = (root) NOPASSWD: /bin/systemd-inhibit
then press ctrl+o to save the file, attention, visudo tends to add a .tmp extension to the file, which makes it deactivated, so when you've pressed ctrl+o, you need to remove the .tmp extension from the file to save (press 4 times backslash) and then press enter.
To exit nano press ctrl+x

After that, you could run systemd-inhibit with root rights. Just, you will properly run jack_capture (or what ever) with just user rights, to do so, the comand will be:

Code: Select all

sudo systemd-inhibit su YourUserName -c jack_capture
That will run systemd-inhibit with the root privileges and jack_capture as user.

You could put a alias in your ~/.bashrc for that to reduce the typing. :)
alias NOSUSPEND=' sudo systemd-inhibit su YourUserName -c '
Then you could run whatever program you wont as user, with the inhibit block bit set with root privileges.


hope it helps finally. :)
On the road again.
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

falkTX wrote:if you have KDE you can just click on the battery icon and uncheck "enable power management".
at least on 14.04 it prevents the computer from going to sleep while idle.
Sure, I should have said originally that this is what I've been doing ever since caffeine stopped working. And now that caffeine-indicator is an option, that works too, and far better than the battery option because at least ther's some visual reminder of the state.

So yes, this works. But I would really prefer not to have an entire separate, manual thing to do and then to manually change back again. I want to just run a script or command so that it's automatically tied to the operation in question.

I'll look over the privilege points above re: systemd…
Aaron Wolf
Music teacher, scholar
http://wolftune.com
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

Good to know that all the hacks tramp mentioned are possible. However, it looks like everything would be solved if caffeine's `caffeinate` function gets fixed. It was just updated to use xdg-screensaver and the error from before went away, but the solution isn't there yet. See https://bugs.launchpad.net/caffeine/+bug/1638042 (and if anyone here feels they could offer assistance on that bug, that would be superb! tramp, maybe your points about systemd-inhibit and using that could be helpful there?)
Aaron Wolf
Music teacher, scholar
http://wolftune.com
tramp
Established Member
Posts: 2347
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 466 times

Re: how to avoid computer suspension while using jack capture?

Post by tramp »

wolftune wrote:tramp, maybe your points about systemd-inhibit and using that could be helpful there?
Maybe, . .
However, here is a little command-line tool in c, to do that. copy and save it as nosuspend.c

EDIT: remove copied source and makefile, as it leads to a copy&paste error in the makefile. Seems the code tag didn't respect tabulators here. However, the source is now on github here:

https://github.com/brummer10/nosuspend

open a root terminal and run make install, after that you could simply avoid suspending your system by run the app with nosuspend prefix

Code: Select all

nosuspend jack_capture
nosuspend will set the look with the 0/root UID set, but the application (here jack_capture) will run in user space.
No hacks in sudors or ~/bashrc are needed.

By the way, there is a request/patch on systemd's github page to allow the set root UID for systemd-inhibit with a configuration option in login.conf, but it is a Year old now, so , . . .
Last edited by tramp on Wed Nov 02, 2016 4:18 am, edited 1 time in total.
On the road again.
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: how to avoid computer suspension while using jack capture?

Post by wolftune »

wow, thanks for all those details. How does this relate to what caffeine does? I mean, it does seem that caffeine getting fixed will do it. Is there a reason caffeine would or would do the things you are suggesting?
Aaron Wolf
Music teacher, scholar
http://wolftune.com
Post Reply