PDA

View Full Version : [CoD2 Server] OS startup script



raphael
31st May 2023, 00:12
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.

At the same location of your main folder (not in), create a file named startmyserver.sh containing the following:



#!/bin/sh
exec setpriv --reuid=codserver --regid=codserver --clear-groups sh -- <<- 'COD'
HOME=/data/myservercod2
exec env - LD_PRELOAD=$HOME/libcod2_1_3.so $HOME/cod2_lnxded_1_3 +set fs_homepath $HOME +set fs_basepath $HOME +set net_ip 12.34.56.78 +set net_port 28960 +set fs_game "mymod" +exec myserver.cfg +map mp_toujane < /dev/tty 2>&1 | tee -a codserver.log
COD


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



#!/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.

Here are the permissions to allow Linux to run the CoD2 server:

sudo chown -R codserver:codserver /data/myservercod2
sudo find /data/myservercod2 -type d -exec chmod 0770 {} \;
sudo find /data/myservercod2 -type f -exec chmod 0660 {} \;
sudo chmod u+x /data/myservercod2/cod2_lnxded_1_3 /data/myservercod2/startmyserver.sh
sudo chown codserver:codserver /data/myservercod2/libcod2_1_3.so
sudo chmod 660 /data/myservercod2/libcod2_1_3.so


# Access 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)
__________________________________________________


Credits:

- https:// killtube.org/showthread.php?2454-CoD2-Setup-CoD2-on-your-Ubuntu-server
- https:// cod.pm/guide/a7a40b/call-of-duty-1-server-on-linux-installing-and-configuring


If you notice an error, if you know how to improve this, please tell.

raphael
12th August 2023, 06:46
4. Not as root, enter crontab -e


I suggested this because I noticed that when using sudo crontab -e, the scripts seems not to be executed sometimes/regularly (debian aws)