assetto-corsa-web / accweb

Assetto Corsa Competizione Server Management Tool via Web Interface.
MIT License
142 stars 54 forks source link

Unable to stop server from gui #249

Closed 33Fraise33 closed 10 months ago

33Fraise33 commented 1 year ago

Hello,

I have setup accweb like following: running as its own non sudo user, running under winehq-devel (version 8.14). Currently I seem unable to stop a server correctly from the web interface. When clicking the stop button I get the message that the server is stopped but the button stays red. My log is showing:

INFO[0000] accweb: checking for secrets...
INFO[0000] accweb: checking for secrets...
INFO[0000] Public/private keys already exists, not attempting regeneration  privateKeyPath=secrets/token.private publicKeyPath=secrets/token.public
INFO[0000] accweb: initializing...
INFO[0000] boot: calculating acc dedicated server md5sum  md5sum=27b1713bc32d7f389aa0c344e61b9c09
INFO[0000] boot: loaded all configured acc servers       total=1
INFO[0000] boot: checking for outdated acc server instances
INFO[0000] boot: auto starting acc server instances
INFO[0000] initializing web server                       addr="0.0.0.0:8080"
INFO[0014] acc server started                            pid=246 server_id=1691824109
INFO[0060] acc server stopped                            server_id=1691824109

INFO[0103] acc server stopped                            server_id=1691824109
INFO[0107] acc server stopped                            server_id=1691824109
INFO[0107] acc server stopped                            server_id=1691824109

I am getting the same result running the command myself as the acc user compared to running it normally through systemd:

[Unit]
Description=ACCWeb Service
After=network-online.target

[Service]
Type=simple
User=acc
Group=acc
Environment="WINEARCH=win64"
Environment="WINEDEBUG=-all"
ExecStart=/home/acc/accweb/accweb
WorkingDirectory=/home/acc/accweb
SyslogIdentifier=accweb
Restart=always
RestartSec=20
StartLimitInterval=0

[Install]
WantedBy=multi-user.target

I downloaded the accServer binary through steamcmd with: /usr/games/steamcmd +@sSteamCmdForcePlatformType windows +force_install_dir /accserver +login <login> +app_update 1430110 validate +quit

I tried both wine from the debian repos (8.0) and winehq-devel with the same result. This is running on debian12 settings.json: , (notice: "ignorePrematureDisconnects":0)

{"configVersion":0,"serverName":"Server name (by accweb)","password":"","adminPassword":"","spectatorPassword":"","trackMedalsRequirement":0,"safetyRatingRequirement":-1,"racecraftRatingRequirement":-1,"ignorePrematureDisconnects":0,"dumpLeaderboards":0,"isRaceLocked":0,"randomizeTrackWhenEmpty":1,"maxCarSlots":30,"centralEntryListPath":"","shortFormationLap":0,"allowAutoDQ":0,"dumpEntryList":0,"formationLapType":3,"carGroup":"FreeForAll"}
Fedemarley commented 11 months ago

Yeah I'm having the same issue with the latest version, I'm unable to stop servers from the web interface, or actually, they stop running but the button remains red still saying "Stop", and I'm unable to modify the settings of the server. It's best to revert to older versions I'm afraid.

kslen commented 10 months ago

Finally spotted the issue.

So, no big news here in terms of a solve, outside of a realization that this started happening after I moved to a new server running Debian 12.2 from my old server running Debian 11.8. It just took a while before I needed to make changes to a config and then found that I couldn't stop ports as before, coinciding with the upgrade to 1.22.0.... Derp.

If I manually kill the accServer.exe process through CLI, accweb more or less immediately picks up on it and the red stop button turns into a green start button as one would expect, so the PID is sort of correct, however; the issue is that the PID listed in accweb on the Debian 12.2 server, is incorrect for the following reason.

The PID 436 listed in accweb on a running port, looks as follows in the process list:

ps aux | grep 436
acc          436  0.0  0.3 2671772 12272 ?       S    Nov21   0:00 start.exe /exec

While the actual accServer.exe binary running the port has PID:

ps aux | grep 1694712062
acc          520  2.1  0.6 2130464 26780 ?       Sl   Nov21  25:57 Z:\home\acc\accweb\config\1694712062\accServer.exe

On the Debian 11.8 server, there's no reference to start.exe /exec at all. :S

So, the solution for now is to use a ports config directory ID to identify the actual PID, then killing it off manually.

Example as per the output above:

ps aux | grep 1694712062
kill 520

I wish was a GO programmer and could provide you with a patch, but alas - I hope this will be of help. I gladly offer my time to assist in testing and could also be persuaded to give you access to the machine if firing up a Debian 12.8 install isn't trivial.

kslen commented 10 months ago

Greetings again.

Had another poke at this to see if I could launch cmd via Wine in a console without start.exe doing the fork thing - and here's my findings.

Simply running the command:

wine cmd

Results in:

ps aux | grep cmd
acc         2423  0.1  0.3 2669660 12384 pts/1   S+   01:33   0:00 C:\windows\system32\cmd.exe
acc         2426  0.0  0.0   6332  2124 pts/0    S+   01:33   0:00 grep cmd

However, trying to run the binary transparently, meaning that bash yeets itself and the connection to the console becomes cmd.exe with the following command (If I were to overly explain it for good measure, resulting in the connection to the server getting closed when you type "exit" in favor of being returned to bash):

exec wine cmd -my

Results in:

ps aux | grep cmd
acc         2278  0.1  0.3 2671744 12396 pts/1   Ss+  01:32   0:00 start.exe /exec cmd
acc         2343  0.0  0.3 2669660 12368 pts/1   S+   01:32   0:00 C:\windows\system32\cmd.exe -my
acc         2346  0.0  0.0   6332  1980 pts/0    S+   01:33   0:00 grep cmd

Looking at the source, it does seem that exec is called to execute wine.

Once again, hope this is of use in resolving this issue. :)

kslen commented 10 months ago

Alright, well, at least I made things a bit less of a struggle for myself by writing the following aptly named script.

Paste the following into a file named stop.sh:

#!/bin/bash
if [ -z $1 ]; then
        echo "[!] No config dir ID specified!"
        echo "    You'll find it in the accweb GUI at the far end of the line beneath the name of the server you want to stop."
        exit 
else
        PID=$(ps aux | grep $1 | grep accServer.exe | awk -F ' ' '{print $2}' )
fi
if [ $PID != $PID ]; then
        echo "[i] accServer.exe with config dir ID $1 isn't running."
else
        echo "[x] accServer.exe with config dir ID $1 with PID $PID is running. Terminating."
        kill $PID
fi

Then make the file executable:

chmod +x stop.sh

Usage and output examples:

./stop.sh
[!] No config dir ID specified!
    You'll find it in the accweb GUI at the far end of the line beneath the name of the server you want to stop.

./stop.sh 1695077022
[x] accServer.exe with config dir ID 1695077022 and PID 1774 is running. Terminating.

./stop.sh 1695077022
[i] accServer.exe with config dir ID 1695077022 isn't running.

As mentioned in the script, you'll find the config dir ID for the server you want to stop in the accweb GUI and here's a screenshot for good measure: image

Hopefully someone with the competence to fix this issue will come along and be inspired by my observations and duct-tape workaround. :)

kslen commented 10 months ago

Made a tiny update to the stop.sh script to eliminate the tedious and unproductive output when running it without specifying a config dir ID.

kslen commented 10 months ago

Just wanted to take the opportunity to inform that the issue has been resolved by the lead dev. New version is on its way. :)