Manage server FiveM (restart/start/stop/screen/status) on linux

Hi !
I would like to add my small contribution for the management of a server FiveM under linux. I know there are already several topics, but I find some are incomplete or not practical uses, that’s why I created my own script.

Nothing complicated to use it.

You will need :

  • Server Linux
  • Server FiveM
  • A mouse
  • A keyboard
  • Putty (or other)
  • You need ton install screen on your debian distrib’ : sudo apt install screen / sudo yum install screen

What does this script do?

It allows to start, restart, stop, screen, and check the status of its server FiveM. But not only!
It also restart mysql, clear the server cache and restart sessionmanager.


Putty

I will not show you how to use putty, it’s way too simple.

  1. Open putty and connect to your linux server.
  2. Once connected, navigate to your FiveM directory via the command cd
  3. Once you are at the root of your server, use the wget command
wget https://raw.githubusercontent.com/HalCroves/Fivem-Serveur-management/master/manage.sh

  1. Technically, you should have a file named manage.sh at the root of your directory

  2. Now, edit this files. Two solutions, via the editor (vim/nano…), or via your ftp if you are a slacker. I will use nano.

  3. Edit the manage.sh vith the command nano manage.sh. You go into edit mode
    image

  4. Arrived at this stage, You only have to modify a few lines.

    • The messages that will be displayed in the chat when restarting

      1. MSG_180 = message send 3 minutes before restarting server
      2. MSG_60 = message send 1 minute before restarting server
      3. MSG_30 = message send 30 seconds before restarting server
    • The folder where your server is located (root). Edit the variable FIVEM_PATH

8.Once modified, you just have to do CTRL + X, type O and press ENTER


Use script

/!\ At the first use, the fivem server must be completely off, because here I use as the name of screen fxserver

  1. To use this script, you must be at the root of your fivem server (ex: /home/FiveM).

    I advise you to use the dos2unix command (apt-get install dos2unix) to convert your file to the correct format.
    Like this :

    dos2unix manage.sh
    

    And you need to add permissions on this file :

    chmod -R 755 manage.sh
    
  2. Now, we simply use the command ./manage.sh start
    This will start the server.
    image


Other uses

./manage.sh start : start server
./manage.sh stop : stop server
./manage.sh restart : restart server
./manage.sh screen : connect to the screen (console)
./manage.sh status : lets you know if the fivem server is started or not


Add a cron task

If you want to use this script for an automatic reboot at any time, you must create a cron task.

For this, i use crontab -e. You need to defile the file editor with your arrow keys.

Exemple :

Here the server will reboot at 00:00, 12pm, 18pm.

00 00 * * * /home/FiveM/manage.sh restart
0 12 * * * /home/FiveM/manage.sh restart
0 18 * * * /home/FiveM/manage.sh restart

Once modified, you just have to do CTRL + X, type O and press ENTER

I do not know if I would update this post and the file. It was just to share.

Cordially,

Hal.

15 Likes

Hi o7,

You need to go in your fivem server installation directory, where all the necessary files for your fivem server have been extracted.

For you, i think is fxserver-data.

For me, it’s the fivem server installation directory (/home/FiveM)

o7,
Everything seems ok. Now edit the mange.sh with notepad++ or sublime text. It will be easier for you.

Check at line 16, and replace “/home/Fivem” by “home/fx-server” and save file with CTRL + S

If your server is turned on, turn off the. Now, with putty, connect you in your server, and type :

cd /home/fxserver

And type :

./manage.sh start
1 Like

it stucks on “Redémarrage de mysql !”

Comment or remove this :

		echo -e "$ROUGE Redémarrage de mysql !$NORMAL"
		sudo service mysql restart

Or install sudo.

This is just a fantastic share. Thanks so much for taking the time to post it!

Don’t work

Hi,

Your replie is so detailled, thanks ! I take out my crystal ball :male_detective:

The script works, I’ve been using it for several years.
If you do not know how to use chmod : https://www.computerhope.com/unix/uchmod.htm

1 Like

Have you got discord?

Nop sorry.


Says its started but not showing anything in server list

Edit: In manage.sh its setup by default to read from fivem path/server-data btw.

FIXED by changing all path locations

Hi i have little problem … When its auto restart message is not poping up … and Screen proces for example “723” its same not changed id of screen… people ingame have same id … so its only kicking players not deleting old screen and creating new proces for start … I have Debian 9 any tips please. Thanks

Why on earth do u wanna restart a mysql database ???

@Aurelie_Tanghe, @HalCroves, this is an English only forum.

i wanna shre my edit of this script…

#!/bin/bash

WIT="\033[0;39m"
ROOD="\033[1;31m"
GROEN="\033[1;32m"
GEEL="\033[1;33m"
PAARS="\033[1;35m"

LOL="\033[1;36m"


MSG_180="Une tempête approche, dans 3 minutes la ville sera rasé !"
MSG_60="Une tempête est aux portes de la ville, fuyez pauvres fous !"
MSG_30="Mon dieu !! Dans 30 secondes vous serez tous morts si vous ne fuyez pas !"

FIVEM_PATH=/home/fivem
SCREEN="ARRYION"

cd $FIVEM_PATH	
running(){
    if ! screen -list | grep -q "$SCREEN"
    then
        return 1
    else
        return 0
    fi
}	

case "$1" in
    # -----------------[ Start ]----------------- #
    start)
	if ( running )
	then
		echo -e ""
	    echo -e "$LOL BOT:$ROOD GTA V SERVER IS ALREADY RUNNING!! $WIT"
	    echo -e ""
	    echo -e "$LOL BOT:$PAARS STOP THE SERVER FIRST: $GEEL./manage.sh stop $WIT"
	    echo -e "$LOL BOT:$WIT OR"
	    echo -e "$LOL BOT:$PAARS RESTART SERVER:        $GEEL./manage.sh restart $WIT"
	    sleep 2
	else
		echo -e ""
        echo -e "$LOL BOT:$WIT STARTING THE GTA V SERVER "
		screen -dm -S $SCREEN
		sleep 2
		screen -x $SCREEN -X stuff "cd /home/fivem/server-data && bash /home/fivem/run.sh +exec server.cfg
		"
		sleep 20
		screen -x $SCREEN -X stuff "restart sessionmanager
		"
		echo -e "$LOL BOT:$GROEN SERVER HAS STARTED $WIT"
		sleep 2
	fi
    ;;
    # -----------------[ Stop ]------------------ #
    stop)
	if ( running )
	then
		echo -e ""
		echo -e "$LOL BOT:$WIT STOPPING THE GTA V SERVER"
        screen -S $SCREEN -p 0 -X stuff "`printf "say $MSG_30\r"`";sleep 10
		screen -S $SCREEN -X quit
		sleep 5
        echo -e "$LOL BOT:$WIT THE GTA V SERVER HAS STOPPED"
        sleep 5
        echo -e "$LOL BOT:$WIT REMOVING CACHE FOLDER"
		rm -R /home/fivem/server-data/cache/
		sleep 5
		echo -e "$LOL BOT:$ROOD CACHE FOLDER HAS BEEN REMOVED $WIT"
		sleep 5
		echo -e "$LOL BOT:$ROOD THE GTA V SERVER HAS STOPPED $WIT"
		sleep 2
	else
		echo -e ""
	    echo -e "$LOL BOT:$ROOD THE GTA V SERVER IS NOT RUNNING!!! $WIT"
	    echo -e ""
	    echo -e "$LOL BOT:$PAARS USE THE COMMAND: $GEEL./manage.sh start $WIT"
	    sleep 2
	fi
    ;;
    # ----------------[ Restart ]---------------- #
	restart)
	if ( running )
	then
		echo -e ""
	    echo -e "$LOL BOT:$WIT THE GTA V SERVER WAS RUNNING"
	    sleep 5 
		echo -e "$LOL BOT:$WIT STOPPING THE GTA V SERVER"
		screen -S $SCREEN -p 0 -X stuff "`printf "say $MSG_30\r"`"; sleep 10
		screen -S $SCREEN -X quit
	    sleep 5
        echo -e "$LOL BOT:$WIT GTA V SERVER HAS STOPPED "
	    sleep 5  
        echo -e "$LOL BOT:$WIT REMOVING CACHE FOLDER"
		rm -R /home/fivem/server-data/cache/
		sleep 5
		echo -e "$LOL BOT:$ROOD CACHE FOLDER HAS BEEN REMOVED $WIT"
		sleep 5
        echo -e "$LOL BOT:$WIT STARTING THE GTA V SERVER"
		screen -dm -S $SCREEN
		sleep 5
		screen -x $SCREEN -X stuff "cd /home/fivem/server-data && bash /home/fivem/run.sh +exec server.cfg
		"
		sleep 20
		screen -x $SCREEN -X stuff "restart sessionmanager
		"
	else
		echo -e ""
	    echo -e "$LOL BOT:$WIT THE GTA V SERVER IS NOT RUNNING"
	    sleep 5
        echo -e "$LOL BOT:$WIT STARTING THE GTA V SERVER "
		screen -dm -S $SCREEN
		sleep 5
		screen -x $SCREEN -X stuff "cd /home/fivem/server-data && bash /home/fivem/run.sh +exec server.cfg
		"
		sleep 20
		screen -x $SCREEN -X stuff "restart sessionmanager
		"
	fi
		echo -e "$LOL BOT:$GROEN SERVER HAS STARTED $WIT"
		sleep 2
	;;	
    # -----------------[ Status ]---------------- #
	status)
	if ( running )
	then
	    echo -e "$GROEN THE GTA V SERVER IS RUNNING $WIT"
	else
	    echo -e "$ROOD THE GTA V SERVER IS NOT RUNNING $WIT"
	fi
	;;
    # -----------------[ Screen ]---------------- #
    screen)
        echo -e "$GROEN Server screen [$SCREEN]. $WIT"
        screen -R $SCREEN
    ;;
	*)
    echo -e "$GEEL Use: $WIT ./manage.sh {start|stop|status|screen|restart}"
    exit 1
    ;;
esac

exit 0

Just Change the location or what ever…
But i guess u can think for ya self XD

1 Like

Could you share what’s different that warrants an edit?

  • messages are in english XD
  • when use restart it will not not give error it has not found no cache folder
  • and i don’t know i love the style more then he had…
  • ow and it don’t restart mysql because it’s useless to restart database( when use like mariadb or mysql)

And i don’t say it’s better i just share what and how i have it now maybe some one will like it :wink:

WHEN SERVER IS RUNNING AND RESTART
11

STOPPING SERVER
22

RESTART AND SERVER WAS NOT RUNNING
33

SERVER STOPPING BUT IS ALREADY STOPPED
111

STARTING SERVER WAS NOT RUNNING
1111

STARTING SERVER BUT WAS ALREADY RUNNING
2222

2 Likes

It seems a little confusing as to what “root” the file belongs. If my structure is:

/home/me/fivem/artifacts <-- Location of artifacts
/home/me/fivem/server-data <-- location of server.cfg

How would this be setup? Would the .sh file be located with the server.cfg and the FIVEM_PATH be the location of artifact’s run.sh?

@Yarpii , I’m trying out your copy and there’s an odd behavior on ./manage.sh restart Instead of the three minute, one minute and 30 second warning, the server only gets the 30 second warning, and the server does restart in 30 seconds. Is your copy altered to do that or is it something wrong with the script?

zz

zzz

screen -x $SCREEN -X stuff "cd /home/fivem/server-data && bash /home/fivem/run.sh +exec server.cfg

just change location have u have it
i have just copy and past what i had and what works for me

  • Just follow his instruction with installing but use my .sh and u will get the right result