Cldfire / mc-server-wrapper

Lightweight Minecraft server wrapper binary for Discord chat bridge + enhanced management tools
Apache License 2.0
18 stars 2 forks source link

Run from systemd unit file. #12

Open Doty1154 opened 1 year ago

Doty1154 commented 1 year ago

Hey I'm trying to run this from a systemd unit file on a up to date ubuntu server. I previously used https://github.com/marcsello/minecraftd So it's running from a specific user account and directory. It sounds like the binary doesn't not like running from systemd for some reason. However if i run it manually from the "minecraft" user account in the /opt/minecraft folder your program works without issue(cool!) Here's the issue i get for the systemd unit with debug systemd turned on:

Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: Will spawn child (service_enter_start): /opt/minecraft/.cargo/bin/mc-server-wrapper Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: Passing 0 fds to service Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: About to execute /opt/minecraft/.cargo/bin/mc-server-wrapper Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: Forked /opt/minecraft/.cargo/bin/mc-server-wrapper as 1527 Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: Changed dead -> running Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: Job 4668 mc-server-wrapper.service/start finished, result=done Apr 02 02:59:29 minecraft systemd[1]: Started mc-server-wrapper. ░░ Subject: A start job for unit mc-server-wrapper.service has finished successfully ░░ Defined-By: systemd ░░ Support: http://www.ubuntu.com/support ░░ ░░ A start job for unit mc-server-wrapper.service has finished successfully. ░░ ░░ The job identifier is 4668. Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: User lookup succeeded: uid=997 gid=998 Apr 02 02:59:29 minecraft systemd[1527]: mc-server-wrapper.service: Executing: /opt/minecraft/.cargo/bin/mc-server-wrapper Apr 02 02:59:29 minecraft mc-server-wrapper[1527]: Error: Resource temporarily unavailable (os error 11) Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: Child 1527 belongs to mc-server-wrapper.service. Apr 02 02:59:29 minecraft systemd[1]: mc-server-wrapper.service: Main process exited, code=exited, status=1/FAILURE

Here is my systemd unit file, I've tried different types, using simple and then not specifying it. I also tried specifying kill mode/killsignal and not using these options.

[Unit] Description=mc-server-wrapper After=network-online.target

[Service] Type=simple ExecStart=/opt/minecraft/.cargo/bin/mc-server-wrapper WorkingDirectory=/opt/minecraft Restart=always User=minecraft Group=minecraft KillMode=process KillSignal=SIGINT

[Install] WantedBy=multi-user.target

Cldfire commented 1 year ago

Hmm, interesting!

The best bit of information about what's going on is in this log line:

Apr 02 02:59:29 minecraft mc-server-wrapper[1527]: Error: Resource temporarily unavailable (os error 11)

Looking around the internet, I see a wide variety of possibilities for what that could mean.

Are there any logs from mc-server-wrapper itself you can share? Any kind of panic / backtrace information?

Doty1154 commented 11 months ago

Hey, i know it's been a while since i posted. But. I got this working by simply using screen to open mc-server-wrapper in a active terminal session. I believe your package just exits once it sees that it's not running interactively(?) At least this is my theory. I think long term maybe adding a -D flag or something where there isn't a tui but just a background process would be great in the future : )

Here's the config i'm using rn.. It doesn't exit appropriately so systemd ends up waiting like 2 minutes during shutdown and kills the process.. that sucks.. I'm not enough of a systemd wizard to figure out a better solution : p


[Unit]
Description=mc-server-wrapper
After=network-online.target

[Service]
Type=simple
ExecStart=screen -D -m /opt/minecraft/.cargo/bin/mc-server-wrapper
WorkingDirectory=/opt/minecraft
Restart=always
User=minecraft
Group=minecraft
KillMode=process
KillSignal=SIGCONT
RestartSec=30

[Install]
WantedBy=multi-user.target
Cldfire commented 7 months ago

Oh neat!

If I ever spend time on this project again I'll look into cleaning that up. I haven't played MC for a while so I don't have much of a reason to work on this tool.