Running Server in Background ============================ When you start your server, the text you write then goes into the server process: you can't use your Linux normally anymore. If you run your server in a VPS, closing the SSH window will not stop your server, but when you will reconnect to the VPS, the server console will be gone. A solution is to run the server in the background, to achieve this, we will use **tmux**. You will be able to detach from the server console, keeping it running in the background. You will also be able to reattach to your server to go back to its console, even after you closed your Linux session. Installing tmux --------------- tmux can be installed on Debian/Ubuntu (which most of the servers use) using the following command: .. code-block:: bash sudo apt install tmux Starting a tmux session ----------------------- To start a new session, simply enter ``tmux`` and you'll enter the new session. .. note:: When you are in a tmux session, you'll see a green line at the bottom like in the figure below. .. figure:: images/tmux_green_line_bottom.png A tmux session with green line at bottom showing some information about the session Detaching from a tmux session ----------------------------- To detach from a tmux session, do exactly like this: 1. Press ``Ctrl + b`` 2. Release all keys 3. Press ``d`` Managing tmux sessions ---------------------- To list existing sessions, type ``tmux ls``. .. figure:: images/tmux_ls.png Listing active tmux sessions As you can see in the figure above, the id of the session we created previously is 0. Type the following command to attach it. .. code-block:: bash tmux attach -t 0 To kill this session, type: .. code-block:: bash tmux kill-session -t 0 Now you can create session, run your cod server in it, detach from it and close your Linux session. When you connect next time, the server would still be running in the tmux session. Automating with a script ------------------------ Let's make a script that will do everything. Assuming you already have a script to start your server, this new script will execute your current start script. For clarity, go to the directory containing your start script, in my case, the path is /home/raph/myserver, and my start script is named start.sh as you can see: .. image:: images/tmux_server_ls.png Now create a script called ``startbackground`` or whatever you like and paste the following in it. .. code-block:: bash #!/bin/bash SVR_DIR="$HOME/myserver" SESSION_NAME="myserver_session" tmux new-session -d -s "$SESSION_NAME" tmux send-keys -t "$SESSION_NAME" "$SVR_DIR/start.sh" .. note:: Replace start.sh by your current filename if needed. Replace "$HOME/myserver" by your own path if needed. .. tip:: The most convenient way to edit files is using a cli text editor like `nano `_ or `fresh `_. Now make the file executable and run it: .. code-block:: bash chmod +x startbackground ./startbackground The server should be running now. You can list tmux sessions to verify. Note ---- .. caution:: When you want to do heavy tests on your server, like try to debug stuff etc, use a normal session instead of tmux, it's more reliable and avoids confusions. Use tmux when your server is ready to be played on. Credits ------- - Run the server in background: `Raph's cod1 tutorials `_