Using systemd to start a FiveM server on linux

I’m trying to setup a systemd for a .sh file to start up a FiveM server on linux. I fixed a couple of error that came out of it before like a permissions error and now I start it up but it says “loaded” and not “active” which I was hoping for, then at the bottom I see “Started server2 service” even though it is not started.

hmm, i’m not experienced with linux but do u start it as it says?

this is very easy

first create a file called fivem.service

then inside the file add the following

[Unit]
Description=FiveM Server

[Service]
WorkingDirectory=/opt/fivem/
ExecStart=/bin/sh run.sh
KillMode=process

[Install]
WantedBy=multi-user.target

make sure you edit the working directory to match were you have the fivem installed, after that its a simple case of creating the service and starting it like so

create link
systemctl enable fivem.service

start service
service fivem start

Hello,

It only work with version 296 of FX build :
https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/296-e24e90af7dcb09b20aaccb29f140e2e59d01ffdb/

New versions won’t work…

How can you tell the server.cfg to your service ? => Edit Found it how.
But, why it took all my CPU when started with systemD, while it’s ok when I start it manually ? ( …/run.sh +exec server.cfg from ssh-bash)

Ok Yoo Etuldan look that !

in your /etc/systemd/system
vi fivem.service

[Unit]
Description=FiveM Server

[Service]
WorkingDirectory=/home/ddrolet/server-data
ExecStart=/bin/sh /home/ddrolet/run.sh +exec server.cfg
KillMode=process

[Install]
WantedBy=multi-user.target

------enable fivem service----
systemctl enable fivem.service

----create link----
service fivem start
----start service----
service fivem start
----Look Status----
systemctl status fivem.service

Try that Brah :slight_smile:

2 Likes

Running FXServer as a system user, is a very bad idea. You should always run it as a standard user, even better if it does not have sudo privileges.

This is what I use, and it works perfectly. It also has the added bonus of running the service as a standard user without additional privileges and will automagically restart if the host OS detects a problem with the service itself.

[Unit]
Description=FiveM Server

[Service]
WorkingDirectory=/fxserver
ExecStart=/bin/sh run.sh
KillMode=process
Restart=on-failure
User=fxserver
Group=fxserver

[Install]
WantedBy=multi-user.target