Running in Docker on a headless server?

Doc Bosher

New member
Hi this may be a really dumb question and I apologize if it is. I am just getting into self-hosting / home lab and was wondering if it would be possible to run mafia in a container on a headless server?

The why:

I usually run mafia on my macbook, everyday after RO I download the latest release from github, fiddle with gatekeeper to allow me to open it, then run autoscend. In aftercore I do party quest, fantasyrealm, piraterealm, cyber realm then overdrink and farm the beach with all my remaining turns, then ascend and repeat. Lately I am doing HCO runs and then will be doing more shrunken runs to HC perm skills. I'm busy with work for the foreseeable future, but when I have more time I'll go back to playing normally.

My desired outcome:

Daily after RO, download the latest release, build an image that run KolMafia, with the Java GUI accessable on a port, ie: `192.168.1.X:7777` and the relay interface on another port, ie: `192.168.1.X:7778`.
Is this possible to achieve with mafia as it is or would it require code changes?

My background is webdev, I'm very new to java/docker/bash scripting etc.

If not, is it possble to achieve this entirly through running mafia through the CLI and some custom ash scripts?

Any help would be appreciated.

Thanks
 
If not, is it possble to achieve this entirly through running mafia through the CLI and some custom ash scripts?

For a number of years, I fully automated Mafia for several characters in an AWS VM, so yes, this is absolutely possible without any modifications.

The easiest way to do this is to run something like `java -jar KoLmafia-*.jar -Djava.awt.headless=true --CLI some_script.txt` where some_script.txt is somewhere in your scripts/ directory and contains something like
Code:
login my_character;
adv * noob cave
login another_character
adv * haunted pantry
exit

I believe you can also point this at an ASH script, and possibly even a JS script. As a bonus, if you sneak in `relay nobrowser` into your script, it'll spawn the relay server on the usual port (60080), which you can then forward as you want so you can poke at the relay browser to see what's happening.

I have personally had better experience with just connecting to Xvfb instead of using headless mode (I think the main thing was that I also ran a chatbot, and chat handling is a bit iffy if in pure headless mode), so that's also an option.

For completeness, I have the following script in $MAFIA_SOURCE/dist:
Code:
#!/bin/sh
git stash
git switch main
git pull --rebase origin main
git stash pop
./gradlew clean
./gradlew shadowJar && java -jar dist/KoL*.jar $@

I then just run `./dist/mafia --CLI meatfarm.txt > dist/meatfarm.out` which then provides a logfile that I can also examine as desired. (Well, okay, I also set DISPLAY=:99 so I can connect to my instance of Xvfb running in the background.)
 
It's been a while since I did fully headless, but it works just as heeheehee said. I do a remote head with port forwarding all the time (both GUI and relay).
 
For a number of years, I fully automated Mafia for several characters in an AWS VM, so yes, this is absolutely possible without any modifications.
Awesome, thank you for the info heeheehee!

It's been a while since I did fully headless, but it works just as heeheehee said. I do a remote head with port forwarding all the time (both GUI and relay).
Would it be possible for you to provide a little more detail on how you do that? Are you using Xvfb or something similar too?


I think I'm going to have a look at Xvfb first as I don't mind some manual imput and I've noticed that occasionally autoscend will fail for me, requiring me to win a fight or spend a couple advs somewhere, so having the GUI is nice.

I'll have a go at getting a docker image running, I'll share if it amounts to anything.
 
I think I'm going to have a look at Xvfb first as I don't mind some manual imput and I've noticed that occasionally autoscend will fail for me, requiring me to win a fight or spend a couple advs somewhere, so having the GUI is nice.
In my script, I typically have `relay nobrowser` as one of the lines so that it spawns up the relay server (without explicitly launching the relay browser), and if it gets stuck I can just open 127.0.0.1:60080/game.php to click on some buttons or execute some /cli commands in chat (which then gets forwarded to the graphical CLI in Mafia).
 
Would it be possible for you to provide a little more detail on how you do that? Are you using Xvfb or something similar too?
I need to try that out someday. I just do it old school with X11 port forwarding. Putty has a checkbox for it. Ssh uses -X. In both make sure to turn on compression it is a big help. Port forwarding the relay browser requires actually specifying the correct ports.
 
Back
Top