I’ve created a switch to start and stop (gracefully) a Minecraft server. Maybe someone will find it useful.
configuration.yaml
switch:
- platform: command_line
switches:
minecraft:
friendly_name: 'Minecraft'
command_on: screen-start.sh
command_off: screen-stop.sh
command_state: screen-check.sh
screen-start .sh
#!/bin/bash
cd $MINECRAFT_DIR
/usr/bin/screen -dmS minecraft /usr/bin/java -Xms1G -Xmx1G -jar minecraft_server.jar nogui
screen-stop .sh
#!/bin/bash
/usr/bin/screen -S minecraft -p 0 -X stuff "/stop"`echo -ne '\015'`
screen-check .sh
#!/bin/bash
if [ "$(/bin/ps | /usr/bin/grep [m]inecraft | wc -l | awk '{print $1}')" == "1" ]
then
exit 0
else
exit 1
fi