I have recently started my Pocketmine server on a VPS in Digitalocean. However, I was wondering how to run the server 24/7, since every time I close the SSH client, (Putty) everything just stops. I figured this out by putting my server on Minepocket-servers and checked when it was last online, which was the time when I closed my SSH client. Anyways, I am running on Ubuntu 16.0.4 in Linux, and I have a basic knowledge of SSH operation commands. I know that pm2 and forever can be used to run Node.js apps indefinitely, (until system stop or reboot, of course) but I don't know how to do the same for Pocketmine. My installation of Pocketmine is located in my root folder, if that matters. Please include all commands required if possible, or at least provide a link or an inkling as to what the commands are. I feel like @HimbeersaftLP would know how to do this since I've been to his server (which seems to be self-hosted on a VPS) Thanks.
Instead of just doing ./start.sh, do screen ./start.sh. Then, do CTRL + A, followed by D to detach from the screen. To get back to the screen and your server's console, do screen -ls and then type screen -r <screen name>. If you have trouble finding which screen your server is on, just do screen -S <name> ./start.sh instead of just screen ./start.sh when you start your server up, so that the screen will have the name you specified when you do screen -ls. Lastly, the screen will be killed whenever you stop your server, unless you set DO_LOOP to yes in start.sh
But how do I set DO_LOOP to yes in start.sh? And when you said that the screen will be killed when I stop the server, which server? The server itself or the Pocketmine instance?
You can use "screen -S <name>" (or just "screen" if you don't want to use more than one screen) and then in the screen window type "./start.sh" then detach (CTRL + A and then D) and then the screen will stay alive when you shut down the server. And you can use "screen -r <name>" (or just "screen -r" if you only have one screen session). About the automatic restart when it crashes, you can either start the server with "./start.sh -l" (recommended) or change this line to "DO_LOOP="yes"".
Code: #!/bin/bash #run on boot with crontab @reboot sh realpathtoscript start # ctrl+B+D to escape after attaching #tmux tab name, should be something you wont use TMS="pmmpbot" #real path of PMMP, expecting start.sh in it DIR="/pmmp/pm/" #user running the script, this is to make sure only THAT specific user runs it, to prevent port binding conflicts SCRIPTUSER="pmmp" #END OF CONFIG CURRENTUSER=$(whoami) if [ "$CURRENTUSER" != "$SCRIPTUSER" ] then echo "Please Run This Script as User: $SCRIPTUSER NOT User:$CURRENTUSER" exit fi start(){ tmux list-session 2>&1 | grep -q "^$TMS:" || tmux new-session -s $TMS -d tmux send-keys -t $TMS:0 "cd $DIR" C-m tmux send-keys -t $TMS:0 "echo Waiting for 3 seconds..." C-m tmux send-keys -t $TMS:0 "sleep 3" C-m tmux send-keys -t $TMS:0 "./start.sh -l" C-m } pmstop(){ tmux send-keys -t $TMS:0 "save-all" C-m tmux send-keys -t $TMS:0 "stop" C-m } stop(){ tmux kill-session -t $TMS } case "$1" in start|r) start ;; stop|h) pmstop stop ;; restart|rs) pmstop stop start ;; attach|s|j) tmux a -t $TMS ;; pmstop|pms) pmstop ;; *) echo "$(basename $0) <start(r)|stop(h)|restart(rs)|attatch(a)|pmstop(pms)>" ;; esac exit 0 I made a bash script to generally make it easier to keep your stuff running, this script should help, keep in mind this utilises TMUX instead of screen you can make it start automatically on reboot with crontabs "@reboot sh /real/path/to/script.sh start" it's also necessary to edit the script config before it would work this starts PMMP it in -l so it automatically restart if crashed/stopped Spoiler: usage start to start it, the () in usage is shortcuts it will also accept stop to stop stop it restart to stop wait start attach is to actually go into the console, use ctrl+b+d to escape, if you haven't modified TMUX before, do not try to use stop command there, it will just get rebooted back pmstop will just run the stop command into PMMP Hope this will help you
tmux is far better Code: # new session # where myserver is the session name. you can have multiple sessions for multiple servers tmux new -s myserver # list sessions tmux ls # attach to a session tmux attach -t myserver # detach from a session # it will continue running in the background tmux detach -s myserver
Thanks for your help! I will keep using screen because I find it way easier to use (although I will try using the tmux and the bash script just to experiment)
cheers then, with enough knowledge you can get away by hacking that script into screen, personally i dont see the differences if all you do is want to keep the server running all time and have a way to access console