Search code examples
processbackgroundubuntu-server

Ubuntu Server - Not able to run server in background


I am running server for Rimworld on RapsberyPi 4B.

I have problem with running it in background, when i start the server:

./Open\ World\ Server

Everything starts but name of CMD is the name of the server and when i close the CMD window server will stop.

I´ve tried many things like & after the command, nohup and others. Also I´ve tried pm2 as it is running my discord bot, but everything that I´ve tried is stil saying that Open World Server is "Stopped".

So what i need is:

  1. Run this server in background
  2. Start this server after restart automatically.

Thanks everyone for help :)


Solution

  • So I have found the solution.

    I´ve tried pm2 many times but never this way.

    nano
    #!/bin/bash
    Command you want to be executed. In my case
    ./Open\ World\ Server
    

    Save this like run.sh or whatever.

    After that simply do this

    pm2 start run.sh
    

    And that is all you need. You can do the same way with minecraft server or other things you want to run in background and start with reboot of your Pi or other devices.