MinecraftServerControl / mscs

Powerful command-line control for UNIX and Linux powered Minecraft servers
https://minecraftservercontrol.github.io
BSD 2-Clause "Simplified" License
485 stars 62 forks source link

Suggestion - open and close firewall #239

Open itbgjm opened 4 years ago

itbgjm commented 4 years ago

In /etc/sudoers

User privilege specification

root ALL=(ALL) ALL minecraft ALL=NOPASSWD:/usr/bin/firewall-cmd --add-port=25565/tcp minecraft ALL=NOPASSWD:/usr/bin/firewall-cmd --remove-port=25565/tcp

msctl file around line 2426

Start each world requested, if not already running.

printf "Starting Minecraft Server:"
for WORLD in $WORLDS; do
  if ! serverRunning $WORLD; then
    printf " $WORLD"
    start $WORLD
  fi
#sudo /usr/bin/firewall-cmd --add-port=$PORT/tcp
sudo /usr/bin/firewall-cmd --add-port=25565/tcp
done

and

line 2469 sendCommand $WORLD "save-all" sendCommand $WORLD "save-off" if [ "$COMMAND" = "force-stop" ]; then forceStop $WORLD else stop $WORLD fi elif [ "$COMMAND" = "force-stop" ]; then printf " $WORLD" forceStop $WORLD fi

sudo /usr/bin/firewall-cmd --remove-port=$PORT/tcp

sudo /usr/bin/firewall-cmd --remove-port=25565/tcp
done
sandain commented 4 years ago

This is not a bad idea, but I wonder if it would be better to implement something like this in the properties files? E.g.:

mscs-prestart-command=sudo /usr/bin/firewall-cmd --add-port=$PORT/tcp
mscs-poststop-command=sudo /usr/bin/firewall-cmd --remove-port=$PORT/tcp

That would allow for much more customization than hard coding something in to the script.

zanix commented 4 years ago

Either this or allow launching another script

sandain commented 4 years ago

That is essentially what I am suggesting with the prestart/poststop commands. However, alternatively we can just update the documentation to mention that something like this is possible*:

mscs-default-server-command=sh prestart.sh && $JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -jar $SERVER_LOCATION/$SERVER_JAR $SERVER_ARGS && sh poststop.sh

*We should verify that this works

zanix commented 4 years ago

That works too, the only advantage I can see with having a separate config option is that it makes it more obvious if someone is looking for the functionality

sandain commented 4 years ago

Actually, modifying the server-command as I suggested above does not work -- It breaks the getJavaPID method.

I think moving forward, the best option would be to add mscs-prestart-command and mscs-poststop-command options to the config files..