Results 1 to 2 of 2

Thread: [CoD2 Server] OS startup script

  1. #1
    Deleter/Deleted
    Join Date
    Jan 2023
    Posts
    76
    Thanks
    40
    Thanked 9 Times in 9 Posts

    [CoD2] Linux startup script

    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:

    PHP Code:
    #!/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>&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:

    PHP Code:
    #!/bin/sh
    tmux new-session --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:

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

    - 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.
    Last edited by raphael; 1st June 2023 at 12:05.

  2. #2
    Deleter/Deleted
    Join Date
    Jan 2023
    Posts
    76
    Thanks
    40
    Thanked 9 Times in 9 Posts
    Quote Originally Posted by raphael View Post
    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)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •