[GUIDE] Hosting a DayZ/Arma server on Linux

Discussion in 'General Discussion' started by Quentix, Jun 29, 2013.

  1. Quentix

    Quentix Member

    Joined:
    Mar 27, 2013
    Messages:
    48
    Likes Received:
    11
    Requirements:

    - A linux PC/Server (in my case a dedicated server with ubuntu 12.04)
    - A windows PC
    - A legit copy of Arma 2 + OA (no support for cracked games)
    - A graphical interface on your server (if you don't have one, I recommend using fluxbox)
    - Recommanded:
    Basic knowledge of linux CLI


    EDIT: I figured out that wine only use one core of the CPU on both of my servers. You can still try to tweak wine and linux to get it running on all the cores but I personally switched to Windows Server for free thanks to Microsoft Dreamspark.


    Step 1 - Installing wine on the server

    We will use the lastest dev version of wine, wich is 1.6

    Add the new wine repository:
    Code:
    sudo add-apt-repository ppa:ubuntu-wine/ppa


    Reload sources and install wine 1.6:
    Code:
    sudo apt-get update && sudo apt-get -y install wine1.6


    If you are running ubuntu 12.10 or higher on a amd64 PC, you will need to add i386 as new foreign architecture:
    Code:
    sudo dpkg --add-architecture i386


    Step 2 - Setting up Wine and dependancies

    Create a new Wine prefix:

    Code:
    WINEARCH=win32 WINEPREFIX=~/.wine winecfg


    This will install and configure wine. Now we will use winetricks to install everything we need.

    Code:
    WINEARCH=win32 WINEPREFIX=~/.wine winetricks --gui

    You might need to install zenity in order to get winetricks working:
    Code:
    sudo apt-get install zenity


    Follow this tutorial's instructions to install all the needed dependencies:

    HTML:
    http://youtu.be/pKJ24Vs4_Yk?t=9m5s



    Step 3 - MySQL

    Install MySQL:

    If you already have a working MySQL server, skip this part.

    Code:
    sudo apt-get install mysql-server


    NOTE: If you want to host a web site, I recommand installing a LAMP package, there is everything you need to host a web site, and mysql is included.

    In order to access your database from another computer, we’ll need to take a look at the config file:

    Code:
    sudo nano /etc/mysql/my.cnf


    Look for “bind-address” and set it to 0.0.0.0 if you want your MySQL server to accept connections from any IP. Be careful with this, it may be dangerous if your server is directly connected to the internet. Press Ctrl + X to quit and press Enter to save.

    Restart MySQL:

    Code:
    sudo service mysql restart


    Login as root:

    Code:
    mysql -u root -p


    Add a new user:

    Code:
    grant all privileges on *.* to 'remote_user'@'123.123.123.123' identified by 'user_password';


    *.* means that this user can acess all databases
    ‘remote_user’ is the username
    ‘123.123.123.123’ is the authorized IP (put % to accept connections from any IP)
    ‘user_password’ is the password

    Create a database:

    Code:
    create database dayz;


    Import database schema using Reality CP with login details above.

    Step 4 - Setting up the server

    We will need a copy of a valid Arma 2 Combined Operations folder. You can try to download it with steam on ubuntu or with wine, but for those who have a dedicated server it will probably not work with steam, because steam requieres a graphic card (I’m not 100% sure about that, but I couldn’t get steam working on my server). However, I recommand uploading your own Arma 2 CO installation to your server (it won’t be a problem if you run the server on a PC that you can physically access) - it took me 3 days to upload my Arma 2 CO installation.

    Now build your server on your PC (If you have no idea how to do that, read the Reality Wiki), configure it ON YOUR PC, make sure everything works on windows before testing on linux, and then upload it to your linux server.

    Type the folowing code to open a Windows Shell:

    Code:
     wineconsole cmd
    NOTE: It’s recommanded to create a new MySQL user for the DayZ server’s hive.
     
  2. Quentix

    Quentix Member

    Joined:
    Mar 27, 2013
    Messages:
    48
    Likes Received:
    11
    Step 5 - Installing Perl and BEC for auto reboots and vehicle spawn

    Download strawberry perl:

    HTML:
    http://strawberry-perl.googlecode.com/files/strawberry-perl-5.18.1.1-32bit.msi


    Install it with wine:

    Code:
    msiexec /i strawberry-perl-5.18.1.1-32bit.msi


    Download this package:

    HTML:
    http://5.135.178.123:81/files/lib.rar


    This archive contains some needed libs to run cleanup, respawn and other perl scripts.
    Now, unrar this archive (unrar x lib.rar) in your strawberry lib folder (C:\StrawberryPerl\perl\site\lib)

    Your virtual C: drive is located in the .wine folder of your /home:

    Code:
    cd ~/.wine/drive_c/strawberry/perl/site/lib
    Now we will need BEC (Battleye Extended Controls):

    HTML:
    http://ibattle.org/downloads/


    Unzip it in a 'BEC' folder in your arma 2 installation, and edit the config file:

    IP and Port should be 127.0.0.1 and 2302, and BePath should be something like this:

    Code:
    BePath = Z:\server\arma\arma2\Arma 2 Operation Arrowhead\dayz_overwatch\BattlEye


    This is really important, if BEC can't find your Beserver.cfg, it won't start.
    The rest of the options should be ok, but don't forget to uncomment the Scheduler = Scheduler.xml and rename A2_Admins.xml to Admins.xml. Also, ServerExeName should be arma2oaserver.exe.

    Download this hand-made package:

    HTML:
    http://5.135.178.123:81/files/scripts.rar



    You will need to adjust thoses files to your configuration:

    - Backup.bat
    - Respawn.bat
    - Cleanup.bat
    - Script.bat
    - Start_script.bat
    - Schedule.xml
    - Server.bat

    When the server reboot, thoses scripts will:

    - Kill Arma 2 server
    - Kill BEC
    - Cleanup/Respawn
    - Backup
    - Launch BEC
    - Launch Arma 2 server
     
  3. J4YpL4Y

    J4YpL4Y New Member

    Joined:
    Apr 20, 2013
    Messages:
    15
    Likes Received:
    0
    Hay nice post just waiting for step 5

    I have my server running fine just having problems with BEC.

    My server is running Overwatch but im having problems with getting auto restarts to work. I have had it all working before but it was Windows server. I start BEC with the normal ./BEC.exe -f Config.cfg and it hangs on waiting for server to start even though the server has been running for hrs.

    Is it down to the server name in the config.cfg?? As arma2oaserver.exe dont show in the prossesis (htop) just the start line looking string.

    I have configured the Restarter.exe from reality pack to start @[email protected]_overwatch. So could the problem be down to the way i start the server????

    Eny help or advice would be grand....
     
  4. J4YpL4Y

    J4YpL4Y New Member

    Joined:
    Apr 20, 2013
    Messages:
    15
    Likes Received:
    0
    Just noted when the game server starts it tells me Beserver.cfg renamed from Beserver_ative_2b.
    But when i look in the Battleye folder its still Beserver_ative_2b.cfg Hmmmmm
     
  5. Quentix

    Quentix Member

    Joined:
    Mar 27, 2013
    Messages:
    48
    Likes Received:
    11
    I'm on vacation ATM so I can't really help you (I'll be home this WE). However, you will need to make a bat file which will:

    1- Kill BEC and arma2oaserver.exe
    2- Save the database (optional)
    3- Call the respawn script (or the pMain function) This is the where it's difficult, installing strawberry Perl with wine works, but the bat file that installs the Perl modules didn't work for me. You'll need to do this on your PC and manually upload the modules to your server (I'll make an archive with everything needed inside)
    4 - Some other scripts (bans etc...)
    5- Launch Arma 2 Server
    6- Launch BEC

    This way, with BEC correctly configured, your server will auto-restart and do everything that is necessary for a DayZ server.
    You may have problems with BEC launching the .bat because it's launched from BEC and this .bat will kill BEC, so it will stop the .bat and auto-kill itself. The solution to this problem is to make another .bat which will open another shell that will not be killed by the .bat

    I may not be clear, so let me know if you don't understand something.
     
  6. J4YpL4Y

    J4YpL4Y New Member

    Joined:
    Apr 20, 2013
    Messages:
    15
    Likes Received:
    0
    I can not get BEC to connect to the server let alone run a scedule and call a .bat

    Perl is installed using Perl_setup.sh

    Will you not end up with lots of terminals open after sevrel restarts?

    Thanks for reply
     
  7. indepth

    indepth Member

    Joined:
    Feb 4, 2013
    Messages:
    98
    Likes Received:
    17
    what's the performance of the server under linux?
     
  8. Quentix

    Quentix Member

    Joined:
    Mar 27, 2013
    Messages:
    48
    Likes Received:
    11
    I can't tell you precisely what performance you'll get; with wine, sometimes it's faster than windows itself, but sometimes it's slower than windows. I'll do a comparative test of windows vs Linux on my PC, but results won't be representative or what you'll get on your PC/server.

    @J4YpL4Y: You need to install strawberry Perl with wine, because the server is running with wine, and also BEC. Otherwise you won't be able to execute scripts on reboots. The virtual Windows environment cannot interact with Linux (I've search a lot, but I didn't find anything)
     
  9. J4YpL4Y

    J4YpL4Y New Member

    Joined:
    Apr 20, 2013
    Messages:
    15
    Likes Received:
    0
    @indepth i can confirm prformance is good and linux is very stable imo. My linux server was up for 364days without issue the only reason for restart was linux update. I am running 3 cod4 , 2 mohaa 1 dayz and 2 csgo. and all is good.

    @Quentix Strawberry perl is installed but still BEC will not connect to the server. No faults in the log. No conflicts with firewall. Config is correct. It dont happen very often but im stuck........
     
  10. Quentix

    Quentix Member

    Joined:
    Mar 27, 2013
    Messages:
    48
    Likes Received:
    11
    Try to launch BEC after the Arma server, in the .bat script, just add pings to wait:

    Code:
    ping 127.0.0.1 -n 15 >NUL
    I think you are launching BEC and the Arma server at the same time, but the Arma server is loading slowly and BEC just timeout and close. I may be wrong, but I think this is your problem.
     
  11. J4YpL4Y

    J4YpL4Y New Member

    Joined:
    Apr 20, 2013
    Messages:
    15
    Likes Received:
    0
    No as i said in my first post the server is online and i has been for hrs before i start BEC. The amount of time has no afect.

    I use the Restarer.exe from the Reality server pack running with wine. after the server is up and running i try to start BEC.

    By using the Restarter. all i have to do in the .bat called by BEC in the scedule is kill arma2oaserver.exe and it will auto restart.
     
  12. Quentix

    Quentix Member

    Joined:
    Mar 27, 2013
    Messages:
    48
    Likes Received:
    11
    Maybe it's BEC trying to connect when the server isn't really ready to accept rcon connections. Try to do as I said, make a batch script launched by BEC in schedule operations which launch another batch script in another shell/window that will kill Arma AND BEC, and launch some scripts, and then launch Arma server and launch BEC, but only after 30 pings launch BEC. It may sound complicated, but I will post my scripts and everything needed.
     
  13. J4YpL4Y

    J4YpL4Y New Member

    Joined:
    Apr 20, 2013
    Messages:
    15
    Likes Received:
    0
    If you could post your script that would be grate i will edit the dir.

    Rcon works fine i am running tsw and thats all good. I have been using it to send server restart warnings and restart from it also.
     
  14. Quentix

    Quentix Member

    Joined:
    Mar 27, 2013
    Messages:
    48
    Likes Received:
    11
    I'm also using TSW, but you should use it only to generate BEC schedule file, not sending warning messages and server reboot. Using BEC is more complicated but it's more flexible and stable, and once you got it, you can do everything you want.
    I'll also post an example of BEC schedule file and config file, with all the needed scripts.
     
  15. indepth

    indepth Member

    Joined:
    Feb 4, 2013
    Messages:
    98
    Likes Received:
    17

    I have no doubt that linux is stable & performance is good for lots of thing, but running Windows binary under wine always scare me on a production point of view ! :p
     
  16. Fentus

    Fentus Member

    Joined:
    Aug 31, 2013
    Messages:
    70
    Likes Received:
    7
    I keep getting this as a response in the command line for BEC:
    fixme:iphlpapi:GetExtendedTcpTable ulAf = 23 not supported
    fixme:iphlpapi:GetExtendedUdpTable ulAf = 23 not supported

    Any ideas?
     
  17. Kakusha

    Kakusha New Member

    Joined:
    Jun 8, 2013
    Messages:
    23
    Likes Received:
    1
    Nice tutorial!
    I've run dayz on headless remote CentOS with wine for a long time too so here's my tips in case you need...

    The server's reliability is guaranteed but when it comes to BEC, I got no luck when i tried first time.
    So i had to dispense with BEC and take other measures to manage the server.
    Here's a substitution in case you cannot manage to run BEC.
    Scheduler : cron is far better.
    Rcon : if you need some rcon commands automatically executed, you can use this module written in php
    https://github.com/R4Z0R49/DayZAdmin/blob/master/modules/rcon.php
    and this is an example of usage of above script which is set for "say" command.
    Code:
    #!/usr/local/bin/php -q
    <?php
    $serverip = "127.0.0.1";
    $serverport = "2302";
    $rconpassword = "PASS";
     
    //$cmd = "say -1 SystemCron: === TEST arg is ".$argv[1]." ===";
    $cmd = "say -1 SystemCron: === Server Restart after $argv[1] min ===";//CHANGE HERE
     
    function strToHex($string)
    {
        $hex='';
        for ($i=0; $i < strlen($string); $i++)
        {
            $hex .= dechex(ord($string[$i]));
        }
        return $hex;
    }
     
    function hexToStr($hex)
    {
        $string='';
        for ($i=0; $i < strlen($hex)-1; $i+=2)
        {
            $string .= chr(hexdec($hex[$i].$hex[$i+1]));
        }
        return $string;
    }
     
    function computeUnsignedCRC32($str){
      sscanf(crc32($str), "%u", $var);
      $var = dechex($var + 0);
      return $var;
    }
     
    function dec_to_hex($dec)
    {
        $sign = ""; // suppress errors
    $h = null;
        if( $dec < 0){ $sign = "-"; $dec = abs($dec); }
     
        $hex = Array( 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5,
                      6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 'a',
                      11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e',
                      15 => 'f' );
         
        do
        {
            $h = $hex[($dec%16)] . $h;
            $dec /= 16;
        }
        while( $dec >= 1 );
     
        return $sign . $h;
    }
     
    function get_checksum($cs)
    {
        $var = computeUnsignedCRC32($cs);
    //echo "crchex: ".$var."<br/>";
    $x = ('0x');
    $a = substr($var, 0, 2);
    $a = $x.$a;
    $b = substr($var, 2, 2);
    $b = $x.$b;
    $c = substr($var, 4, 2);
    $c = $x.$c;
    $d = substr($var, 6, 2);
    $d = $x.$d;
    return chr($d).chr($c).chr($b).chr($a);
    }
     
    function rcon($serverip,$serverport,$rconpassword,$cmd){
    $passhead = chr(0xFF).chr(0x00);
    $head = chr(0x42).chr(0x45);
    $pass = $passhead.$rconpassword;
    $answer = "";
    $checksum = get_checksum($pass);
     
    $loginmsg = $head.$checksum.$pass;
     
    $rcon = fsockopen("udp://".$serverip, $serverport, $errno, $errstr, 1);
    stream_set_timeout($rcon, 1);
     
    if (!$rcon) {
    echo "ERROR: $errno - $errstr<br />\n";
    } else {
    fwrite($rcon, $loginmsg);
    $res = fread($rcon, 16);
     
    $cmdhead = chr(0xFF).chr(0x01).chr(0x00);
    //$cmd = "Players";
    $cmd = $cmdhead.$cmd;
    $checksum = get_checksum($cmd);
    $cmdmsg = $head.$checksum.$cmd;
    $hlen = strlen($head.$checksum.chr(0xFF).chr(0x01));
     
    fwrite($rcon, $cmdmsg);
    $answer = fread($rcon, 102400);
     
    if ( strToHex(substr($answer, 9, 1)) == "0"){
    $count = strToHex(substr($answer, 10, 1));
    //echo $count."<br/>";
    for ($i = 0; $i < $count-1; $i++){
    $answer .= fread($rcon, 102400);
    }
    }
    //echo strToHex(substr($answer, 0, 16))."<br/>";
    //echo strToHex($answer)."<br/>";
    //echo $answer."<br/>";
    $cmd = "Exit";
    $cmd = $cmdhead.$cmd;
    $checksum = get_checksum($cmd);
    $cmdmsg = $head.$checksum.$cmd;
    fwrite($rcon, $cmdmsg);
    }
     
    return $answer;
    }
    $res = rcon($serverip,$serverport,$rconpassword,$cmd);
     
    if($res == NULL){
        $cnt=0;
        while($res==NULL){
            $res = rcon($serverip,$serverport,$rconpassword,$cmd);
            sleep(1);
            $cnt++;
            if($cnt > 15) break;
        }
    }
    ?>
     
  18. Kakusha

    Kakusha New Member

    Joined:
    Jun 8, 2013
    Messages:
    23
    Likes Received:
    1
    Other several tips.
    Perl and running routine scripts written in perl : you needn't install strawberry perl or something like that. maybe your distribution has a package manager such as yum, apt-get, and so on. just install perl package.
    then try cpan to install some mandatory modules.
    for example, these are what i needed to install so as to run Reality's perl scripts(e.g. db_migration.pl, db_utility.pl, db_spawn_vehicles.pl...)
    Code:
    cpan
    install DBI
    install DBIx::Migration
    install DBIx::Migration::Directories
    install DBIx::Transaction
    that's enough to run these .pl file.

    and those who runs a server which doesn't have a monitor or window.
    I'm using Xvfb.
    Code:
    yum install xorg-x11-server-Xvfb
    and this is my current startup script for example. not very nice though.
    Code:
    #!/bin/sh
    cd SRVROOT
    isAliveXvfb=`ps -ef | grep Xvfb | grep -v grep | wc -l`;
    if [ $isAliveXvfb -eq 1 ]; then
            echo "Xvfb:runnning"
    else
            echo "Xvfb:stopping"
            Xvfb :1 -screen 0 800x600x16 &
            echo "Xvfb:started"
    fi
    nice -n -10 wine SRVROOT/Expansion/beta/arma2oaserver.exe "[email protected];@reality_1.chernarus;ca" "-name=Reality" "-profiles=dayz_1.chernarus" "-config=dayz_1.chernarus/config_chernarus.cfg" "-cfg=dayz_1.chernarus/basic.cfg" "-cpuCount=4" "-maxMem=2047" "-exThreads=7" "-noPause" "noSound" &
    
    oh and don't forget to set a full-path so that these scirpts works properly via cron.
     
  19. Quentix

    Quentix Member

    Joined:
    Mar 27, 2013
    Messages:
    48
    Likes Received:
    11

    Can you post the full log ?
    Usually you can ignore thoses fixme: errors.

    @Kakusha: Thanks for your tips, about the perl script yes you can run them on your native linux but there's no way of doing that with a bat file executed with BEC or any bat executed in the virtual windows environment. Anyway I moved to Epoch now and I use MySQL routines for cleanup and other stuff on the database.
    And about Xvfb, yes it works but you need a real X server in order to run Steam (both on linux or windows), and X2Go works fine and is much more secure than a simple VNC server.

    Anyway thanks for your tips :)
     
  20. wshaler

    wshaler New Member

    Joined:
    Aug 26, 2013
    Messages:
    25
    Likes Received:
    0

Share This Page