Hello
I have been trying to get a game server to run as a service and am having issues getting the stop command to run the script that I wrote for it to use. The script when ran by itself works fine. When I issue the systemctl stop command it just kills that process without running the script it seems and I would like to get it to save before it just kills the service. My service file is
[Unit]
Description=Minecraft_Server
Wants=network.target
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/home/bulbasaur/Minecraft/Java/Nightcraft
User=bulbasaur
Group=bulbasaur
ExecStart=/usr/bin/screen -DmS NightcraftJava /home/bulbasaur/Minecraft/Java/NightcraftJava/run.sh
ExecStop=/usr/bin/screen -p NightcraftJava /home/bulbasaur/Minecraft/Java/NightcraftJava/stop.sh
[Install]
WantedBy=multi-user.target
My start script is:
#!/bin/bash
#set location
cd /home/bulbasaur/Minecraft/Java/Nightcraft
#start game
java -Xmx4G -Xms4G -jar server.jar -nogui
My stop script is this
#!/bin/bash
#stop warning
screen -S NightcraftJava -X stuff $’/say server shutting down in 5 minutes\n’
#delay d=days h=hours m=minutes s=seconds
sleep 5m
#shutdown
screen -S NightcraftJava -X stuff $‘stop\n’
when I check the status after issuing the stop command I get this
minecraftjava.service - Minecraft_Server
Loaded: loaded (/etc/systemd/system/minecraftjava.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-04-14 23:58:35 EDT; 11min ago
Main PID: 2075974 (code=exited, status=1/FAILURE)
Apr 14 23:58:01 bulbasaur systemd[1]: Started Minecraft_Server.
Apr 14 23:58:34 bulbasaur systemd[1]: Stopping Minecraft_Server…
Apr 14 23:58:34 bulbasaur systemd[1]: minecraftjava.service: Main process exited, code=exited, status=1/FAILURE
Apr 14 23:58:35 bulbasaur systemd[1]: minecraftjava.service: Failed with result ‘exit-code’.
Apr 14 23:58:35 bulbasaur systemd[1]: Stopped Minecraft_Server.
and the log file says this
[23:58:07] [main/INFO]: Environment: authHost=‘https://authserver.mojang.com’, accountsHost=‘https://api.mojang.com’, sessionHost=‘https://sessionserver.mojang.com’, servic>
[23:58:08] [main/WARN]: Ambiguity between arguments [teleport, destination] and [teleport, targets] with inputs: [Player, 0123, @e, dd12be42-52a9-4a91-a8a1-11c01849e498]
[23:58:08] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[23:58:08] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, targets] with inputs: [0.1 -0.5 .9, 0 0 0]
[23:58:08] [main/WARN]: Ambiguity between arguments [teleport, targets] and [teleport, destination] with inputs: [Player, 0123, dd12be42-52a9-4a91-a8a1-11c01849e498]
[23:58:08] [main/WARN]: Ambiguity between arguments [teleport, targets, location] and [teleport, targets, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[23:58:08] [main/INFO]: Reloading ResourceManager: Default, afk display v1.1.0.zip, armor statues v2.8.1.zip, armored elytra v1.0.3.zip, coordinates hud v1.2.0.zip, double >
[23:58:10] [Worker-Main-11/INFO]: Loaded 7 recipes
[23:58:10] [Worker-Main-11/WARN]: Found validation problem in {minecraft:entities/ender_dragon}.pools[0].entries[0]: Unknown loot table called minecraft:entities/reference/>
[23:58:10] [Worker-Main-11/INFO]: Loaded 945 advancements
[23:58:12] [Server thread/INFO]: Starting minecraft server version 1.16.5
[23:58:12] [Server thread/INFO]: Loading properties
[23:58:12] [Server thread/INFO]: Default game type: SURVIVAL
[23:58:12] [Server thread/INFO]: Generating keypair
[23:58:12] [Server thread/INFO]: Starting Minecraft server on 192.168.0.18:25565
[23:58:12] [Server thread/INFO]: Using epoll channel type
[23:58:12] [Server thread/INFO]: Preparing level “Nightcraft JS1”
[23:58:12] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld
[23:58:14] [Server thread/INFO]: Preparing spawn area: 0%
[23:58:14] [Server thread/INFO]: Preparing spawn area: 0%
[23:58:14] [Server thread/INFO]: Preparing spawn area: 0%
[23:58:14] [Server thread/INFO]: Preparing spawn area: 0%
[23:58:15] [Server thread/INFO]: Preparing spawn area: 0%
[23:58:15] [Server thread/INFO]: Preparing spawn area: 84%
[23:58:15] [Server thread/INFO]: Time elapsed: 2725 ms
[23:58:15] [Server thread/INFO]: Done (2.870s)! For help, type “help”
[23:58:15] [Server thread/WARN]: Trying to add entity with duplicated UUID 291dfbec-2b7b-4c2b-9899-f665ea53af5d. Existing minecraft:armor_stand#27, new: minecraft:armor_sta>
[23:58:34] [Server console handler/ERROR]: Exception handling console input
java.io.IOException: Input/output error
at java.io.FileInputStream.readBytes(Native Method) ~[?:?]
at java.io.FileInputStream.read(FileInputStream.java:279) ~[?:?]
at java.io.BufferedInputStream.read1(BufferedInputStream.java:290) ~[?:?]
at java.io.BufferedInputStream.read(BufferedInputStream.java:351) ~[?:?]
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) ~[?:?]
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) ~[?:?]
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) ~[?:?]
at java.io.InputStreamReader.read(InputStreamReader.java:181) ~[?:?]
at java.io.BufferedReader.fill(BufferedReader.java:161) ~[?:?]
at java.io.BufferedReader.readLine(BufferedReader.java:326) ~[?:?]
at java.io.BufferedReader.readLine(BufferedReader.java:392) ~[?:?]
at zg$1.run(SourceFile:95) [server.jar:?]
and when I run the stop stript I get this output which is what I want
[00:13:05] [main/WARN]: Ambiguity between arguments [teleport, destination] and [teleport, targets] with inputs: [Player, 0123, @e, dd12be42-52a9-4a91-a8a1-11c01849e498]
[00:13:05] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[00:13:05] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, targets] with inputs: [0.1 -0.5 .9, 0 0 0]
[00:13:05] [main/WARN]: Ambiguity between arguments [teleport, targets] and [teleport, destination] with inputs: [Player, 0123, dd12be42-52a9-4a91-a8a1-11c01849e498]
[00:13:05] [main/WARN]: Ambiguity between arguments [teleport, targets, location] and [teleport, targets, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[00:13:05] [main/INFO]: Reloading ResourceManager: Default, afk display v1.1.0.zip, armor statues v2.8.1.zip, armored elytra v1.0.3.zip, coordinates hud v1.2.0.zip, double >
[00:13:07] [Worker-Main-13/INFO]: Loaded 7 recipes
[00:13:07] [Worker-Main-13/WARN]: Found validation problem in {minecraft:entities/ender_dragon}.pools[0].entries[0]: Unknown loot table called minecraft:entities/reference/>
[00:13:07] [Worker-Main-13/INFO]: Loaded 945 advancements
[00:13:09] [Server thread/INFO]: Starting minecraft server version 1.16.5
[00:13:09] [Server thread/INFO]: Loading properties
[00:13:09] [Server thread/INFO]: Default game type: SURVIVAL
[00:13:09] [Server thread/INFO]: Generating keypair
[00:13:10] [Server thread/INFO]: Starting Minecraft server on 192.168.0.18:25565
[00:13:10] [Server thread/INFO]: Using epoll channel type
[00:13:10] [Server thread/INFO]: Preparing level “Nightcraft JS1”
[00:13:10] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld
[00:13:12] [Server thread/INFO]: Preparing spawn area: 0%
[00:13:12] [Server thread/INFO]: Preparing spawn area: 0%
[00:13:12] [Server thread/INFO]: Preparing spawn area: 0%
[00:13:12] [Server thread/INFO]: Preparing spawn area: 0%
[00:13:12] [Server thread/INFO]: Preparing spawn area: 2%
[00:13:13] [Server thread/INFO]: Time elapsed: 2546 ms
[00:13:13] [Server thread/INFO]: Done (2.732s)! For help, type “help”
[00:13:13] [Server thread/WARN]: Trying to add entity with duplicated UUID 291dfbec-2b7b-4c2b-9899-f665ea53af5d. Existing minecraft:armor_stand#27, new: minecraft:armor_sta>
[00:13:48] [Server thread/INFO]: [Server] server shutting down in 5 minutes
[00:18:48] [Server thread/INFO]: Stopping the server
[00:18:48] [Server thread/INFO]: Stopping server
[00:18:48] [Server thread/INFO]: Saving players
[00:18:48] [Server thread/INFO]: Saving worlds
[00:18:48] [Server thread/INFO]: Saving chunks for level ‘ServerLevel[Nightcraft JS1]’/minecraft:overworld
[00:18:48] [Server thread/INFO]: ThreadedAnvilChunkStorage (Nightcraft JS1): All chunks are saved
[00:18:48] [Server thread/INFO]: Saving chunks for level ‘ServerLevel[Nightcraft JS1]’/minecraft:the_nether
[00:18:48] [Server thread/INFO]: ThreadedAnvilChunkStorage (DIM-1): All chunks are saved
[00:18:48] [Server thread/INFO]: Saving chunks for level ‘ServerLevel[Nightcraft JS1]’/minecraft:the_end
[00:18:48] [Server thread/INFO]: ThreadedAnvilChunkStorage (DIM1): All chunks are saved
[00:18:48] [Server thread/INFO]: ThreadedAnvilChunkStorage (Nightcraft JS1): All chunks are saved
[00:18:48] [Server thread/INFO]: ThreadedAnvilChunkStorage (DIM-1): All chunks are saved
[00:18:48] [Server thread/INFO]: ThreadedAnvilChunkStorage (DIM1): All chunks are saved
what am I doing wrong here?
I did look in the journalctl and saw that it is ignoring the script for stopping for some reason…
Apr 14 23:50:18 bulbasaur systemd[1]: Stopping Minecraft_Server…
Apr 14 23:50:18 bulbasaur screen[2065149]: Must be connected to a terminal.
Apr 14 23:50:18 bulbasaur systemd[1]: minecraftjava.service: Control process exited, code=exited, status=1/FAILURE
Apr 14 23:50:18 bulbasaur systemd[1]: minecraftjava.service: Main process exited, code=exited, status=1/FAILURE
Apr 14 23:50:20 bulbasaur systemd[1]: minecraftjava.service: Failed with result ‘exit-code’.
Apr 14 23:50:20 bulbasaur systemd[1]: Stopped Minecraft_Server.
Apr 14 23:57:51 bulbasaur systemd[1]: /etc/systemd/system/minecraftjava.service:12: Failed to parse signal name, ignoring: /usr/bin/screen -p NightcraftJava /home/bulbasaur/Minecraft/Java/Nightcraft/stop.sh