I want a user to run a specific process on the system with a negative nice value. I can't simply fork the process to background as this specific program is a minecraft server and I rely on the command line to control the server.
My current bash script looks like this (the important part):
sleep 10 && \
sudo renice -n $NICENESS $(ps -u $(id -u) -o "%p:%c" | sed -n "s/:java$//p") & \
java -Xmx8G -Xms2G -jar minecraft_server.jar nogui
sleep
simply delays execution of renice
. renice
itself uses ps
to check for a java process using the users own ID. There might be other instances of java spawning under different users, but the minecraft server runs under its own user minecraft.
I obviously don't want to enter a password every time I start the server.
from /etc/sudoers:
minecraft ALL = NOPASSWD: /etc/renice
Is there a more elegant way to do this? Simply using nice
is not an option, sudo nice bash
in combination with the NOPASSWD: option would be a great security issue.
nice
doesn't seem to do it, I had to set both, using-
. – Baarn Nov 28 '13 at 14:38priority
to -10 andnice
to -15 and I always get "permission denied" even when I try to use "nice -n -2" on something. Do I have to reboot? I just logged out and in again as per this advice. – IpsRich Jul 05 '19 at 12:25priority
setting does have effect, but thenice
setting only allows me to reduce the priority. When I start something with the default priority, it's now -10. I canrenice
the process to -9 but then can'trenice
it back to -10. – IpsRich Jul 08 '19 at 11:12hard
that caused the problems. I changed it to-
instead and all works fine now. This answer helped me get to the bottom of it. I think the problem was that I had a soft limit that was getting in the way, perhaps overriding the hard limit somehow. Anyway,-
instead ofhard
fixed it for me. – IpsRich Jul 08 '19 at 12:48