Hi
Here is a tutorial to learn how to start your CoD2 server automatically when Linux starts.
Using this technique, you can continue to use the OS while the server is running, you can also exit the SSH and come back later to regain control.
__________________________________________________
# Script to start the CoD2 server. //Optional if you already have one.
Spoiler:
At the same location of your main folder (not in), create a file named startmyserver.sh containing the following:
- codserver is the user created using sudo useradd -r -s /usr/sbin/nologin codserver on Debian.
- /data/myservercod2 is the folder containing the main folder.
- 12.34.56.78 is the internal IP.
- mymod is the fs_game folder, located in /data/myservercod2.
# Script to run the CoD2 server start script when Linux starts.
1. Enter sudo apt install tmux -y
2. Enter echo $HOME
At this location, create a file named startupcod2.sh containing the following:
PHP Code:
#!/bin/sh tmux new-session -d -s cod2server tmux send-keys -t cod2server 'sudo su' ENTER tmux send-keys -t cod2server 'cd /data/myservercod2' ENTER tmux send-keys -t cod2server './startmyserver.sh' ENTER
3. Enter sudo chmod +x startupcod2.sh
4. Not as root, enter crontab -e
If it asks for a text editor, I suggest Nano.
At the end of the file, paste @reboot sh $HOME/startupcod2.sh
Nano: CTRL + o = save. CTRL + x = close.
____________________________________
# Set files permissions. //Optional if already done or if not using the optional above script.
Spoiler:
Here are the permissions to allow Linux to run the CoD2 server:
When the CoD2 server has been started, you can access it by entering (not as root) tmux attach -t cod2server.
To exit tmux while keeping the server running, press CTRL + b, then press just d.
If you want to remove the session, enter tmux kill-session -t cod2server. (it closes the server)
__________________________________________________