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 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.
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.