mscs icon indicating copy to clipboard operation
mscs copied to clipboard

Suggestion - open and close firewall

Open itbgjm opened this issue 5 years ago • 5 comments

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

itbgjm avatar Feb 22 '20 19:02 itbgjm

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.

sandain avatar May 06 '20 21:05 sandain

Either this or allow launching another script

zanix avatar Jun 09 '20 20:06 zanix

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

sandain avatar Jun 09 '20 20:06 sandain

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

zanix avatar Jun 09 '20 21:06 zanix

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

sandain avatar Jun 10 '20 00:06 sandain