Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen/tmux is not needed #13

Closed
lzap opened this issue Mar 20, 2020 · 6 comments
Closed

Screen/tmux is not needed #13

lzap opened this issue Mar 20, 2020 · 6 comments

Comments

@lzap
Copy link

lzap commented Mar 20, 2020

Hey, stumbled upon your scripts. Nice, however tmux is not needed at all, systemd can create FIFO for STDIN:

# cat /etc/systemd/system/minecraft@.service
[Unit]
Description=Minecraft Bedrock: %i
After=network.target

[Service]
Sockets=minecraft@%i.socket
WorkingDirectory=/opt/minecraft/bedrock/%i
User=minecraft
Group=minecraft
ProtectHome=true
Type=simple
ExecStart=/opt/minecraft/bin/start-mc
ExecStop=/usr/bin/sh -c "echo 'say Server shutdown in 5 seconds' >/run/minecraft@%i/stdin"
ExecStop=/usr/bin/sleep 5
ExecStop=/usr/bin/sh -c "echo stop >/run/minecraft@%i/stdin"
TimeoutStopSec=30
Restart=always
RestartSec=600s
StandardInput=socket
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

# cat /etc/systemd/system/minecraft@.socket
[Unit]
BindsTo=minecraft@%i.service

[Socket]
RuntimeDirectory=%N
ListenFIFO=%t/%N/stdin
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=minecraft
SocketGroup=minecraft

# echo "say HELLO WITHOUT TMUX" >/run/minecraft@survival_easy1/stdin

This is much more secure, I am working on implementing SELinux policy on top of that. With tmux that is not possible. FYI if you want to simplify your scripts a bit.

@TapeWerm
Copy link
Owner

TapeWerm commented Mar 21, 2020

Interesting, I will try that later. That could get rid of server_do(). The jank that is server_read() would live on albeit scraping journalctl instead of tmux. I wonder if journalctl can automatically parse the join/leave messages and push to the IRC bot and any future web hooks I've considered adding (likely just a line of wget). That would make the jank that is MCBElog.sh unneeded with up to 1 minute less delay as it would read on push instead of scraping once a minute. Only possible downside is while tmux confuses people having to use journalctl to see the output of a command echo'd to the pipe is also going to confuse some users.

Edit: I'm definitely putting the instance name in the description later. That was an oversight of mine, thank you.

@TapeWerm
Copy link
Owner

I addressed the description lacking instance name, I'll play with a separate branch trying systemd sockets later this weekend. Gotta apply for classes, read backup logs, and other stuff first.

@TapeWerm
Copy link
Owner

TapeWerm commented Mar 30, 2020

Branch werm_socket has some progress on scraping logs the same way I use tmux capture-pane. I'll work on it more tonight probably.
Edit: Most probable result of this is I drop tmux from the server and drop support for tmux sessions entirely. For now the IRC bot will stay in a tmux session.

@TapeWerm
Copy link
Owner

TapeWerm commented Mar 30, 2020

I'm having a lot of trouble getting input logged the way tmux did. I just want standard in to be logged in the journal but I haven't found anything in systemd or Bash for that.
Edit: I'm gonna have to hold off on this, just spent a few hours and made zero progress. Got other things that need to be done before tomorrow morning, unless someone finds out how to take standard in and put that in the journal or in standard output which does go to the journal.
Edit 2: ExecStart=/bin/bash -c 'tee | LD_LIBRARY_PATH=. ./bedrock_server' does not output the input in journalctl.
Edit 3: Alt plan could be the reason I need stdin in logs is I scrape journalctl and use what I put in stdin as a cutoff point for parsing it. I could use journalctl timestamps and parse those and compare dates to find such. Honestly might be a better system but would need a big rewrite to the backup scripts.
Edit 4: I fixed the backup script with a major refactor, testing and an update should be out soon.

@TapeWerm
Copy link
Owner

Latest 2 commits fix this issue. My services and scripts now use systemd sockets and journalctl. I may readd tmux compatibility later but that is irrelevant to this issue, the services will continue to use systemd sockets.

@lzap
Copy link
Author

lzap commented Mar 31, 2020

Wow that was fast, sorry I had bunch of github notifications to read through. This is cool.

# Thanks for sockets Lukáš Zapletal

This is not really necessary, it only pollutes such a nice and clean (tmux-free) config file now :-)

I am planning an article for opensource.com about SELinux policy and this repo will be totally featured as the recommended way! Kudos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants