Keep server running on VPS (Ubuntu 16.04)

Ask questions about dedicated servers here and we and other users will do our best to answer them. Please also refer to the self-help section for tutorials and answers to the most commonly asked questions.
Post Reply
lowheartrate
A semi-regular
A semi-regular
Posts: 28
Joined: Thu Jul 02, 2015 2:54 pm
Contact:

Keep server running on VPS (Ubuntu 16.04)

Post by lowheartrate » Wed Aug 30, 2017 3:06 pm

I am currently running a single core Ubuntu 16.04 VPS and put my fivem gtav server on there. It seems the only way I can keep the server running is if I am signed into my VPS via SSH PuTTy and when I close out of PuTTy my server shuts down. I'd like to figure out how the server can remain running even when I am not signed into the vps constantly.
Image

User avatar
hiimcody1
Staff
Staff
Posts: 1287
Joined: Wed Dec 28, 2011 4:59 pm

Re: Keep server running on VPS (Ubuntu 16.04)

Post by hiimcody1 » Wed Aug 30, 2017 7:03 pm

The "screen" program is what you'd want to use, or "tmux"

rushy
New to forums
New to forums
Posts: 5
Joined: Wed Dec 14, 2016 6:45 pm
Contact:

Re: Keep server running on VPS (Ubuntu 16.04)

Post by rushy » Wed Aug 30, 2017 7:08 pm

You can use screen for this, runs the process in its own 'container' that stays running when you disconnect via ssh.

First make sure screen is installed with

Code: Select all

sudo apt-get install screen
Start up the server with its start up script using

Code: Select all

screen -S Screenname -d -m /path/to/running/script.extension
*You can change Screenname to a name you want

To attach the screen, to view it for potential logs or to view it

Code: Select all

screen -R Screenname
When done, detach from the screen with “Ctrl-a” “d”

lowheartrate
A semi-regular
A semi-regular
Posts: 28
Joined: Thu Jul 02, 2015 2:54 pm
Contact:

Re: Keep server running on VPS (Ubuntu 16.04)

Post by lowheartrate » Wed Aug 30, 2017 7:38 pm

As I was waiting for a response I actually found this article here and now my /etc/rc.local now looks like the following:

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

cd /home/server/server-data
bash /home/server/run.sh +exec server.cfg

exit 0
So with that everytime my VPS is rebooted my FiveM GTA V Server boots up as well but ran into a few issues maybe you can help me solve?
  • Not sure how to get back to server console if I need to run convars or check logs.
  • In order to stop, start, restart the FiveM GTA V Server I need to reboot the VPS machine. Is it possible to create bash scripts to just restart the server instead of having to do the entire machine every single time?!
Any help would be greatly appreciated as currently I am stuck restarting the entire machine every time I want to make changes to the server and if possible would like to continue using this process rather than installing screen.
Image

rushy
New to forums
New to forums
Posts: 5
Joined: Wed Dec 14, 2016 6:45 pm
Contact:

Re: Keep server running on VPS (Ubuntu 16.04)

Post by rushy » Wed Aug 30, 2017 8:01 pm

My instructions with a screen will allow you to attach the screen to input commands if that '/home/server/run.sh' script allows user input

lowheartrate
A semi-regular
A semi-regular
Posts: 28
Joined: Thu Jul 02, 2015 2:54 pm
Contact:

Re: Keep server running on VPS (Ubuntu 16.04)

Post by lowheartrate » Wed Aug 30, 2017 8:34 pm

rushy wrote:My instructions with a screen will allow you to attach the screen to input commands if that '/home/server/run.sh' script allows user input
Awesome, got a screen so the server console is on my "server" screen but still run into my issue, how can I create bash script(s) so I can run something that will restart, stop or start just the GTA V server. I am a bit new to the VPS thing if you couldn't tell :P
Image

rushy
New to forums
New to forums
Posts: 5
Joined: Wed Dec 14, 2016 6:45 pm
Contact:

Re: Keep server running on VPS (Ubuntu 16.04)

Post by rushy » Thu Aug 31, 2017 1:55 am

lowheartrate wrote:
rushy wrote:My instructions with a screen will allow you to attach the screen to input commands if that '/home/server/run.sh' script allows user input
Awesome, got a screen so the server console is on my "server" screen but still run into my issue, how can I create bash script(s) so I can run something that will restart, stop or start just the GTA V server. I am a bit new to the VPS thing if you couldn't tell :P
From what I could tell from the FiveM wiki, the server itself does not have any restart, or Quit commands.

If that is correct:

What you would have to do is
1. Create 'startup script that has the normal screen start.

2. One that kills the screen with the command 'screen -X -S Screenname quit' - Terminating a screen kills the application running within

3. One that 'restarts' - combines the kill command and a screen start afterwards

In my following example I called my screen GTAVScreen, change to what you would like.

#1 (Change to what you used when you manually created the screen, below is just an example):

Code: Select all

#!/bin/sh
screen -S GTAVScreen -d -m /home/server/run.sh +exec server.cfg
#2 - 'quit' script:

Code: Select all

#!/bin/sh
screen -X -S GTAVScreen quit
#3 - 'restart' script

Code: Select all

#!/bin/sh
screen -X -S GTAVScreen quit
sleep 10
screen -S GTAVScreen -d -m /home/server/run.sh +exec server.cfg

^We put a delay in between commands to ensure the quit command went through fully (Just in case)

Of course you will need to chmod them all to make it executable with chmod +x
eg If I made a start.sh script, I would issue chmod +x start.sh (from within the same directory)

To activate them you would use ./start.sh or use the whole path if outside the directory

lowheartrate
A semi-regular
A semi-regular
Posts: 28
Joined: Thu Jul 02, 2015 2:54 pm
Contact:

Re: Keep server running on VPS (Ubuntu 16.04)

Post by lowheartrate » Thu Aug 31, 2017 1:02 pm

Awesome! Thanks so much for the help got the scripts going and they're working great! thank you thank you thank you :D
Image

Post Reply