简体   繁体   中英

Start/Stop Minecraft Server with PHP

For the last 10 hours I have been trying to find a way to start/stop a craftbukkit.jar file that is in the same directory as my php script. I have tried nearly all of the solutions I could find on stackoverflow and none of them worked.

I tried both shell_exec("java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true"); and exec("java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true"); I also tried putting the java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true in a external start.sh file and then running it with exec("start.sh")

What am I doing wrong? It is supposed to create all of the bukkit configuration files when the process is ran (just like it would when you run it on your computer)

I think you need a console to run the server in... i would reccomend a screen session for the server:

To start the server the command could look like this:

exec("screen -S bukkit sh /home/user/bukkit/start.sh")

the -S option is to name the session. so when you want to connect to the console through ssh for example you simply do

screen -r bukkit

maybe you should use absolute paths for the command... not shure if its better or not

there is a way to send some commands to that session to stop the server as well... but i dont remember right now!

if you do not use screen for smth else you could try

exec("killall screen")

to kill all screensessions... but be careful with that because the server might not save recent changes(no shutdown of the bukkit-server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM