Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to autostart Ubuntu headless server?

Discussion in 'Multiplayer' started by tmammela, Nov 26, 2015.

  1. tmammela

    tmammela

    Joined:
    Sep 28, 2015
    Posts:
    27
    There must be people here who run their game servers on Ubuntu servers? How do you start the program when the server starts? I can run it with ./Servername.x86_64 but that's all I know about running programs in Linux. This method is not good because the server will not start if a reboot happens, also the program is tied to the SSH terminal window - if I close it the program closes with it.

    Firewall configuration and overall server installation hardening was easy with guides but I'm having trouble with this one. I heard about this thing called upstart, is that what is used for this kind of thing?
     
  2. tmammela

    tmammela

    Joined:
    Sep 28, 2015
    Posts:
    27
    I'm trying to run my server with upstart, but I get this error:

    Got a SIGABRT while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries
    used by your application.

    Again, it runs fine if I cd to the directory and run ./Server.x86_64 but that same command does not work trough upstart.


    My upstart script:

     
    Last edited: Nov 27, 2015
  3. tmammela

    tmammela

    Joined:
    Sep 28, 2015
    Posts:
    27
    This time with /etc/init.d/ script. I have called sudo update-rc.d vcpr_server defaults but it wont start on boot. I can run it fine manually with: sudo /etc/init.d/vcpr_server

     
  4. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    Can't help you with upstart, but for init.d scripts make sure they are linked to the appropriate runlevel. E.g. make a symbolic link to that file in whatever runlevel you want the server to be started, e.g.
    ln -s /etc/init.d/vcpr_server /etc/rc2.d/S99vcpr_server
     
  5. tmammela

    tmammela

    Joined:
    Sep 28, 2015
    Posts:
    27
    Thanks for response.

    Unfortunately I already have the link in place, so that is not the problem.
     
  6. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    Then I suppose it's because of the missing PATH or something ... I would suggest having it log the output (especially the error output) to a file.
     
  7. tmammela

    tmammela

    Joined:
    Sep 28, 2015
    Posts:
    27
    Okay, I got it working. I'm so confused right now that I don't know what is going on, but here is how I start it now:

    In /etc/rc.local I added this line:

    It runs screen terminal multiplexer as a user and then in that screen session the starting script is run. exec bash makes sure that the screen session won't exit...

    It is important to run as a user not as root, for some reason I get mono errors if run as root.

    My run_server.sh is very simple:

     
  8. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Root doesn't get the same environment as a regular user, and upstart scripts don't get the same environment that you do when you just login via ssh either. So issues with programs not running the same under upstart are almost always something different about the environment. If you do something like the following example it should work fine.

    I su to a different user, and use a shell script to actually run the program instead of starting it directly.




    Code (CSharp):
    1.  
    2. description "game machine server"
    3.  
    4. start on runlevel [1234]
    5. stop on shutdown
    6. script
    7.   chdir /home/gamemachine/app/current/server
    8.   exec sudo -u gamemachine /home/gamemachine/app/current/server/bin/game_machine s
    9. end script
    10.  
    11. respawn
    12.