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

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

It works but restart command just stucks some clue?

try this one if you want to keep using the CLI


or this one for web interface
https://forum.cfx.re/t/release-txadmin-manager-discord-bot-live-console-playerlist-autorestarter/530475

I would like to share my edit of the script.
I add “pkill -9 ld-musl-x86” after the command to kill screen because sometimes it doesn’t kill fivem process when restart and also I edited colours ready for PHP output for some private Server manager tab for admins.

#!/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/username/FiveM
SCREEN="TheBalkanRP-SRV01-test"

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 "<span style="color:blue">BOT<span style="color:red">:<span style="color:green"> $SCREEN <span style="color:orange"> SERVER IS ALREADY RUNNING!!"
	    echo -e ""
	    echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> STOP THE SERVER FIRST!"
	    echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> OR"
	    echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:green"> RESTART SERVER!"
	    sleep 2
	else
		echo -e ""
        echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> STARTING THE <span style="color:green">$SCREEN<span style="color:orange"> SERVER "
		screen -dm -S $SCREEN
		sleep 2
		screen -x $SCREEN -X stuff "cd /home/username/FiveM/server-data && bash /home/username/FiveM/run.sh +exec server.cfg > /home/username/public_html/output.txt
		"
		sleep 20
		screen -x $SCREEN -X stuff "restart sessionmanager
		"
		echo -e "<span style="color:blue">BOT<span style="color:red">: <span style="color:green"> $SCREEN<span style="color:orange"> SERVER HAS STARTED!"
		sleep 2
	fi
    ;;
    # -----------------[ Stop ]------------------ #
    stop)
	if ( running )
	then
		echo -e ""
		echo -e "<span style="color:blue">BOT<span style="color:red">: <span style="color:blue">STOPPING THE <span style="color:green"> $SCREEN<span style="color:orange"> SERVER"
        screen -S $SCREEN -p 0 -X stuff "`printf "say $MSG_30\r"`";sleep 10
		screen -S $SCREEN -X quit
		sleep 5
		pkill -9 ld-musl-x86
		sleep 5
        echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> THE <span style="color:green">$SCREEN<span style="color:orange"> SERVER HAS STOPPED"
        sleep 5
        echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> REMOVING CACHE FOLDER"
		rm -R /home/username/FiveM/server-data/cache/
		rm -rf /home/username/public_html/output.txt
		sleep 5
		echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> CACHE FOLDER HAS BEEN REMOVED!"
		sleep 5
		echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> THE <span style="color:green"> $SCREEN<span style="color:orange"> SERVER <span style="color:red">HAS STOPPED!"
		sleep 2
	else
		echo -e ""
	    echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> THE <span style="color:green"> $SCREEN SERVER <span style="color:red">IS NOT RUNNING!!!"
	    echo -e ""
#	    echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> USE THE COMMAND: $GEEL./manage.sh start $WIT"
	    sleep 2
	fi
    ;;
    # ----------------[ Restart ]---------------- #
	restart)
	if ( running )
	then
		echo -e ""
	    echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> THE <span style="color:green">$SCREEN <span style="color:orange">SERVER <span style="color:green"> WAS RUNNING"
	    sleep 5 
		echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> STOPPING THE <span style="color:green"> $SCREEN<span style="color:orange"> SERVER"
		screen -S $SCREEN -p 0 -X stuff "`printf "say $MSG_30\r"`"; sleep 10
		screen -S $SCREEN -X quit
		sleep 5
	    pkill -9 ld-musl-x86
	  sleep 5
        echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:green"> $SCREEN <span style="color:orange">SERVER HAS STOPPED "
	    sleep 5  
        echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> REMOVING CACHE FOLDER"
		rm -R /home/username/FiveM/server-data/cache/
		rm -rf /home/username/public_html/output.txt
		sleep 5
		echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> CACHE FOLDER HAS BEEN REMOVED!"
		sleep 5
        echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> STARTING THE <span style="color:green"> $SCREEN <span style="color:orange">SERVER"
		screen -dm -S $SCREEN
		sleep 5
		screen -x $SCREEN -X stuff "cd /home/thebalk/FiveM/server-data && bash /home/username/FiveM/run.sh +exec server.cfg > /home/username/public_html/output.txt
		"
		sleep 20
		screen -x $SCREEN -X stuff "restart sessionmanager
		"
	else
		echo -e ""
	    echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> THE <span style="color:green">$SCREEN<span style="color:orange"> SERVER  IS NOT RUNNING"
	    sleep 5
        echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:orange"> STARTING THE <span style="color:green"> $SCREEN<span style="color:orange"> SERVER "
		screen -dm -S $SCREEN
		sleep 5
		screen -x $SCREEN -X stuff "cd /home/fivem/FiveM/server-data && bash /home/username/FiveM/run.sh +exec server.cfg > /home/username/public_html/output.txt
		"
		sleep 20
		screen -x $SCREEN -X stuff "restart sessionmanager
		"
	fi
		echo -e "<span style="color:blue">BOT<span style="color:red">:<span style="color:green"> SERVER HAS STARTED!"
		sleep 2
	;;	
    # -----------------[ Status ]---------------- #
	status)
	if ( running )
	then
	    echo -e "<span style="color:blue">THE <span style="color:green"> $SCREEN<span style="color:blue"> SERVER <span style="color:green">IS RUNNING!"
	else
	    echo -e "<span style="color:blue">THE <span style="color:green"> $SCREEN <span style="color:blue"> SERVER<span style="color:red"> IS NOT RUNNING!"
	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

and php and html part:

 <html lang="en">
   <head>
     <meta char-set="utf-8">
     <title>Server manager</title>
   </head>
   <body>
<table width="200" border="0">
  <tbody>
    <tr>
      <td><form action="start.php" type="post">
		 <input type="submit" value="Start server" /></form></td>
      <td><form action="stop.php" type="post">
		<input type="submit" value="Stop server" /></form></td>
      <td><form action="restart.php" type="post">
		<input type="submit" value="Restart server" /></form></td>
      <td><form action="rmscreen.php" type="post">
		<input type="submit" value="Wipe Screen" /></form></td>
      
    </tr>
  </tbody>
</table>
<form action="start.php" type="post">
</form>
		
</form>
   </body>
 </html>
 <?php
$cmd = '/home/username/FiveM/manage.sh status';
while (@ ob_end_flush()); // end all output buffers if any

$proc = popen($cmd, 'r');
echo '<pre>';
while (!feof($proc))
{
    echo fread($proc, 4096);
    @ flush();
}
echo '</pre>';

?>

you can make other scripts as start.php, restart.php… from this part it is the same as the PHP part above.

 <?php
$cmd = '/home/username/FiveM/manage.sh start';
while (@ ob_end_flush()); // end all output buffers if any

$proc = popen($cmd, 'r');
echo '<pre>';
while (!feof($proc))
{
    echo fread($proc, 4096);
    @ flush();
}
echo '</pre>';

?>

Hello, I have a problem.
When I start my server with the command ./manage.sh start
this error message comes along: There is no screen that can be attached to DragonRP.
please help me…

Because u need screen package for linux.

Ubuntu and Debian
sudo apt install screen
CentOS 
sudo yum install screen

Hello, for me, the command ./manage.sh screen doesn’t work
it said; no sush file or directories.

But restart, start and stop works fine.

Anybody can help me ?
PS: I want to use FXAdmin but I don’t know how to use it in Putty

Hi ! Start and stop its ok for me but reboot automatic dont work … https://prnt.sc/s6sql4

Edit your FiveM server path in the manage.sh
Also, use txadmin. I made a fork of the manage.sh on the repo of the script.

If you need help, open a discussion on my fork of the script :slight_smile:

1 Like