Question Keep console input open on shell script start

rez_spb

New member
Nov 4, 2022
3
0
1
I have migrated to Paper from Spigot setup and I love the performance boost.
I have written a shell script for Spigot server start with a small hack: on start I create named pipe which is passed as a stdin to java process to read from without blocking out further script execution (basically checks and conditions, notifications, emails etc).

The part responsible looks like this:
Bash:
# make named pipe
mkfifo server_console;

# keep it open
exec 3> server_console &

# start the server
java \
<cut here>
-jar server.jar nogui < server_console &>>${_log_file} &
This worked as intended and is still working with spigot: after shell script finishes the named pipe allows to pass commands to the console without any need to keep the java process open on the screen. I run:
Code:
$ echo "command" > server_console
...and it passes the command to the game. No issues.

However that's not the case with Paper core: looks like the core kills the main java process and spawns another one without my fifo input.
I have checked the pids, so I'm pretty sure about process respawning. I need to either disable this respawn or pass my args when respawn happens.
So here's the question: what's the proper way of achieving this in Paper?

Thanks.
 

OmegaWeaponDev

New member
Nov 15, 2022
3
0
1
27
Australia
Try adding a pause at the end of the file. That should keep the window open. Also, it's recommended if you use

java -Xms10G -Xmx10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper.jar --nogui

Those as the startup flags for the server as it will allow for even better performance. Obviously you'd need to adjust the ram amounts in the xms and xmx values. More information can be found from: https://docs.papermc.io/paper/aikars-flags
 

rez_spb

New member
Nov 4, 2022
3
0
1
Try adding a pause at the end of the file. That should keep the window open. Also, it's recommended if you use

java -Xms10G -Xmx10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper.jar --nogui

Those as the startup flags for the server as it will allow for even better performance. Obviously you'd need to adjust the ram amounts in the xms and xmx values. More information can be found from: https://docs.papermc.io/paper/aikars-flags
Thank you for these params, I will definitely look them through. I have cut mine from my output (here) to preserve space, I have some already, but it's always nice to get new recommendations.

As for pause, the thing here is that the wrapper script should continue without stopping. I send minecraft java server process to background, but attach named pipe input which allows interactions with STDIN for the process in BG. Server runs there (in the background) while the main wrapper script continues checks, waits for server start, sends notification emails and finishes gracefully without terminating or interfering with java server in the background. There's also no windows because it's linux terminal without X server. The issue lies when Paper respawns java server process without attaching FIFO to STDIN and there is no way to send input to detached console in this case.

One of conventional 'hacks' is to use tmux or screen with console open, but that still requires manual human switching between them sessions (STDIN attached to console) as opposed to simple writing to named pipe from any terminal, web UI, other integration or script. Vanilla and Spigot have no issue here because server java process does not respawn on start. Paper does.
 

SkytAsul

New member
Dec 20, 2022
6
1
3
Bretagne, France
linktr.ee
Thank you for these params, I will definitely look them through. I have cut mine from my output (here) to preserve space, I have some already, but it's always nice to get new recommendations.

As for pause, the thing here is that the wrapper script should continue without stopping. I send minecraft java server process to background, but attach named pipe input which allows interactions with STDIN for the process in BG. Server runs there (in the background) while the main wrapper script continues checks, waits for server start, sends notification emails and finishes gracefully without terminating or interfering with java server in the background. There's also no windows because it's linux terminal without X server. The issue lies when Paper respawns java server process without attaching FIFO to STDIN and there is no way to send input to detached console in this case.

One of conventional 'hacks' is to use tmux or screen with console open, but that still requires manual human switching between them sessions (STDIN attached to console) as opposed to simple writing to named pipe from any terminal, web UI, other integration or script. Vanilla and Spigot have no issue here because server java process does not respawn on start. Paper does.
I am sorry, I'm not bringing a solution to your issue but simply telling you that it's possible to send text in the stdin of a detached screen session. (and it's probably possible with tmux as well, though I haven't tested it). Check this page: https://unix.stackexchange.com/questions/13953/sending-text-input-to-a-detached-screen
Personally, I find this solution more elegant than using custom FIFOs.