A
Admincraft•5d ago
Cake

Having problems with systemd and tmux

Whenever I run tmux through systemd, it doesn't actually create the tmux session. It works fine if I run tmux directly, but not through systemd. The tmux command in question: tmux -L minecraft new-session -c /srv/minecraft/server -s minecraft -d 'java -Xmx8G -Xms256M -jar paper.jar nogui' (yes I know i'm not using the optimal flags, i'm just setting it up though) If I run has-session to check, it says "no server running on /tmp/tmux-110/minecraft"
Solution:
I figured it out! The user I was running the script as was a system user and so they had nologin as the shell. When I ran it from su -u username -s, it worked fine because I was running it in a shell, but obviously systemd doesn't have that. So I just set the shell environment variable in the systemd unit and it works now...
Jump to solution
3 Replies
Koth
Koth•5d ago
Could be a bunch of things unfortunately It's possible that java isn't available in the systemd env, it's possible that tmux isn't creating a socket directory for itself (lacking permissions to do so). There's a bunch of things that could be going wrong 😅 You can start a minecraft server directly with systemd if you want to avoid tmux related issues entirely. Might be worth trying to isolate if it's an env thing or a tmux thing
Cake
CakeOP•4d ago
Yeah, running Java directly through systemd does work, but it would be nice to be able to reattach at will. I also tried moving the tmux socket but it seemed like no matter where I moved it, I would get the same error in the new directory. And only when using systemd
Solution
Cake
Cake•4d ago
I figured it out! The user I was running the script as was a system user and so they had nologin as the shell. When I ran it from su -u username -s, it worked fine because I was running it in a shell, but obviously systemd doesn't have that. So I just set the shell environment variable in the systemd unit and it works now

Did you find this page helpful?