Guide to running SFBot as Systemd service on Linux

Antworten
Benutzeravatar
ToKsick
Beiträge: 6
Registriert: Sa 10. Okt 2020, 22:42
Hat sich bedankt: 2 Mal
Danksagung erhalten: 3 Mal

Guide to running SFBot as Systemd service on Linux

Beitrag von ToKsick »

Hello,

This topic is for Linux begginers who owns some Linux server and wants to run this bot on it using systemd service.
Notes:
If you copy-paste the code remove the "[root@localhost ~]# "<-- and the space.
Change the: "<your_user>" to user name you are using to connect to your machine.. If you are using root user then change the path /home/<your_user> to /root
  1. Create Linux service user with:

    Code: Alles auswählen

    [root@localhost ~]# useradd -c "SFBot acc" -d /opt/sfbot -s /sbin/nologin sfbot
    
  2. Now we can download the MFBot binary from here: http://www.mfbot.de/en/downloads/ and select the binary which fits your system. In my case I am using x86 architecture cpu so I pick "x86_64/amd64 processors (linux servers with intel processors or similar)"... You might use different one.

    Code: Alles auswählen

    [root@localhost sfbot]# cd /opt/sfbot/
    [root@localhost sfbot]# wget http://www.mfbot.de/Download/latest/MFBot_Konsole_x86_64
    
  3. Create systemd service file.

    Code: Alles auswählen

    [root@localhost sfbot]# nano /etc/systemd/system/sfbot.service 
    
    Copy-paste these lines and save

    Code: Alles auswählen

    [Unit]
    Description=Magical Fidget Bot
    After=syslog.target
    After=network.target
    
    [Service]
    Type=simple
    User=sfbot
    Group=sfbot
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=sfbot
    EnvironmentFile=/etc/sfbot/.env
    WorkingDirectory=/opt/sfbot/
    
    # Change the name of the file "MFBot_Konsole_x86_64" to the different one if you downloaded different executable
    ExecStart="/opt/sfbot/MFBot_Konsole_x86_64"
    
    [Install]
    WantedBy=multi-user.target
    
    Now reload the service files

    Code: Alles auswählen

    [root@localhost sfbot]# systemctl daemon-reload
    
    Now you could execute and see if service is loaded

    Code: Alles auswählen

    [root@localhost sfbot]# systemctl status sfbot.service 
    
    If you now see some lines that looks like this you did this process right

    Code: Alles auswählen

    sfbot.service - Magical Fidget Bot
         Loaded: loaded (/etc/systemd/system/sfbot.service; disabled; vendor preset: enabled)
         Active: inactive (dead)
    
  4. Create environment file for the future exeperiments and so on..
    Create directory for .env file

    Code: Alles auswählen

    [root@localhost sfbot]# mkdir /etc/sfbot
    
    Create the empty .env file

    Code: Alles auswählen

    [root@localhost sfbot]# touch /etc/sfbot/.env
    
    Set the owner of the directory and .env file

    Code: Alles auswählen

    [root@localhost sfbot]# chown -R sfbot:sfbot /etc/sfbot/
    
  5. Prepare the Acc.ini file which you can create on the Windows version of this app.
  6. Upload it to the machine to your /home/<your_user>. For example you can use WinSCP or FileZilla for uploading the file
  7. Copy the file and set the permissions for sfbot to see the file

    Code: Alles auswählen

    [root@localhost ~]# mv /home/<your_user>/Acc.ini /opt/sfbot/ 
    
    Now change the owner to permit sfbot to see the file and "control" it

    Code: Alles auswählen

    [root@localhost ~]# chown sfbot:sfbot /opt/sfbot/Acc.ini
    
  8. If you did everything right you can now execute to start the service:

    Code: Alles auswählen

    [root@localhost ~]# systemctl start sfbot.service 
    
    and to see if service is running:

    Code: Alles auswählen

    [root@localhost ~]# systemctl status sfbot.service 
    
    The output should be something like this

    Code: Alles auswählen

    sfbot.service - Magical Fidget Bot
         Loaded: loaded (/etc/systemd/system/sfbot.service; disabled; vendor preset: enabled)
         Active: active (running) since Sun 2020-10-11 11:09:09 CEST; 1s ago
         Main PID: 104785 (MFBot_Konsole_A)
         Tasks: 4 (limit: 9252)
         CGroup: /system.slice/sfbot.service
                 └─104785 /opt/sfbot/MFBot_Konsole_XXXXX
    
If you want to see the logs execute and scroll down to the latest output:

Code: Alles auswählen

[root@localhost ~]# journalctl -u sfbot
If you have questions feel free to ask :)
Folgende Benutzer bedankten sich beim Autor ToKsick für den Beitrag:
Robin (So 11. Okt 2020, 15:43)
Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 5 Gäste