Search Unity

Opening a linux server with commands?

Discussion in 'Editor & General Support' started by Samuel411, May 19, 2018.

  1. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Hello all!

    I made a Linux dedicated server build in headless mode and am attempting to launch it with some commands and use this code to get them:
    Code (CSharp):
    1. String[] Data = Environment.GetCommandLineArgs();
    2.             if (Data.Length == 3)
    3.             {
    4.                 ip = Data[0];
    5.                 port = int.Parse(Data[1]);
    6.                 serverIp = Data[2];
    7.                 serverPort = int.Parse(Data[3]);
    8.                 Connect();
    9.             }
    10.             else
    11.             {
    12.                 Application.Quit();
    13.             }
    I have the .x86 file in my Linux server (hosted on digitalocean so I only have a command prompt in puTTy). I do not know how to open it however or what to even enter to get to the CommandLineArgs? Any help?
     
  2. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    GetCommandLineArgs() will always include the path as data[0] I believe. Also, you're accessing 4 data parts, while checking for Data.Length == 3. You'd want to check for Data.Length == 5, and starts at [1].
     
    Samuel411 likes this.
  3. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Ah thank you for the reply! What would the command be to launch the game on linux and also input these commands? I'm looking for something like, 'start filepath -cmd1 -cmd2 -cmd3 -cmd4'
     
  4. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
  5. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    This still doesn't help me. I know how to run commands detached from the command line, what I'm looking for specifically is the command to launch a .x86 headless unity build and what I would type following that to input command arguments.
     
  6. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Ah finally got it working.
    Steps to get a Linux headless build running on digitalocean or AWS
    1. Upload your build to a website or dropbox (needs to be an instant download link meaning when the link is opened the file automatically downloads, if you use dropbox you need to just change the end to ?dl=1, for example: https://www.dropbox.com/s/9jicrxd13nklp5o/Server.zip?dl=1)
    2. Download the unzip 'sudo apt-get install unzip'
    3. Download your build 'wget [build download link]'
    4. Unzip the file installed 'unzip Server.zip?dl=1' (for some reason ?dl=1 is still kept in the file extension when using dropbox)
    5. Give yourself permission to use the build file 'sudo chmod +x [build].x86'
    6. Download the following extensions using these commands
    'sudo apt-get install libc6-i386'
    'sudo apt-get install lib32stdc++6'
    7. Finally open your linux server
    './[build].x86 -nographics -cmd0 arg0 -cmd1 arg1 -cmd2 arg 2 -cmd3 arg3...'

    The code I used to get the command line arguments is this:
    Code (CSharp):
    1. for(int i =0; i < Data.Length; i++)
    2.             {
    3.                 if(Data[i] == "-cmd0")
    4.                 {
    5.                     arg0 = Data[i + 1];
    6.                 }
    7.                 if(Data[i] == "-cmd1")
    8.                 {
    9.                     arg1 = Data[i + 1];
    10.                 }
    11.                 if(Data[i] == "-cmd2")
    12.                 {
    13.                     arg2 = Data[i + 1];
    14.                 }
    15.                 if(Data[i] == "-cmd3")
    16.                 {
    17.                     arg3 = Data[i + 1];
    18.                 }
    19.             }
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You should also be able to just scp your build from your desktop computer directly to your virtual machine if it is assigned a public IP address. Mac probably has scp built in, and with Windows you just get a copy of pscp.