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

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

Just had a quick question. Is it possible to change the server restart times? Need to change them for a stream. Thanks!

1 Like

If you’re asking if you can set automatic restarts at certain times, then yes, as mentioned by the OP, you would use a cron job to set automatic restarts. You can set that cronjob to restart as often and at the times you want.

If you’re instead asking about how long the restart pauses prior to it’s restart, yes, just add more sleeps to that function.

Did you try your own script or you just posted it?
Screen stuff commands are broken and the way you resume screens is weird.
Add more conditions maybe? Dynamic timer? You could do much better

Author pretty much stated he’s going to set it and forget it in regards to this script but I’d love to hear what changes you’d implement since I’m using the script. It’s working fine for us but would be interested in hearing what changes or improvements you’d make and why.

I have my own script,
I will share it when i finish some editing (trying to make it user input compatible since i want to share it), maybe in 1 or 2 hours.

I look forward to seeing it!

I was using this script on my debian server, so yes.
I just shared a script with the knowledge I had. If you are not happy, nothing prevents you from doing yours and sharing it.

Any script can be embellished. It just depends on the person
So unpleasant people like you …

Thank you

Happy about what? I don’t even use your script
That was my own opinion, i wrote some stuff you could use to improve your script but i deleted them because you don’t deserve it or even this reply.

Regards
Unpleasant person

I did not intend to modify this script, as mentioned above.
Very good, good day to you.

“Dah bisous ;)”

As much as I love to see useful threads devolve into toxic I-know-you-are-but-what-am-I tennis matches, I just wanted to say Hal, script’s working great for our server. I really appreciate you taking the time and effort to share it.

FXAdmin now also supports scheduled restarts as well as restarts on failure detection.
And it is compatible with windows and linux.
https://forum.cfx.re/t/pre-release-fxadmin-manager-discord-bot-live-console-playerlist-autorestarter/530475/54