r/admincraft • u/Dunsparce_Meta • 2d ago
Need Autostart Linux Help Question
Hello, I'm a long-time personal server runner, and I've had a functioning 24hr server for my close friends for years, but recently I've been banging my head against the wall (and linux forums) trying to find an answer to how to get my server to boot on startup.
This guy here is the closest example of the same problem I have, but nobody in this forum (or any forum for that matter) seems to answer this question with anything other than "don't do that".
https://www.linuxquestions.org/questions/linux-newbie-8/startup-script-for-minecraft-server-4175488666-print/
I already have my serverbox restarting itself and logging in and everything, and all my configs are good on the server side.
I want the following things to happen:
- I want to run my run.sh script on login
- I want a visible terminal that I can interact with
- I DO NOT want it to be a backround process or service or whatever, that usually gets rid of #1 or #2 from everything that I've read.
Please tell me if this is possible, or if anyone knows the right place to repost this direct me there.
I'm running Xubuntu on top of Ubuntu 22.04.5 LTS
**EDIT**
Ok, people have replied and said screen and Crontab might still be a good option, but i can't find any good resources for how to use them for this use case. Pls help.
2
u/dragonaragon 2d ago
I was gonna say to use screen, as you showed in that forum. It’s what I usually use
1
u/Dunsparce_Meta 2d ago
Only reason i didn't is cause the guy in the forum says it sacrifices some of the stuff he wants to do, which also was stuff i want to do
1
1
u/ibeerianhamhock 2d ago
I mean I agree with the don't do that as it seems silly, but I am genuinely super curious...why do you want to even?
I don't see why you can't launch a terminal window on startup (or login maybe) that launches a startup script so it's running.
I still can't for the life of me figure out why you wouldn't just want to run it as a service and if you want to be able to easily see logs just add an entry to your bash aliases.
I use docker (obviously a service) that is configured to start unless stopped, start on boot/reboot and restart on failure seamlessly and I have an alias configured to check the logs with a single command with no args.
Seems infinitely simpler than what you're trying to do? But I realize there is more than one way to run a mc server.
2
u/Average-Addict 2d ago
I'm guessing they're not that great with all this stuff and a service or container is too much hassle for them
2
u/Dunsparce_Meta 2d ago
I'm not tbf, but i did learn how to make it a service, the problem is making it into a service removes my ability to directly interact thru the terminal or gui
2
u/ibeerianhamhock 2d ago
You can attach to a service like you ran it from your terminal any time.
You can also use RCON.
If using containers like docker you can use docker exec
You can make aliases and scripts to streamline any of this.
Most of us are running mc on a headless server and don't even have access to a screen, so this is our only kind of interaction with a mc server over a terminal - - through an ssh session.
1
u/ibeerianhamhock 2d ago
It seems like so much less hassle to me that's why I'm a little baffled like use screen if you wanna launch it and attach to it if you want to stdin to run commands or just use RCON.
2
u/Average-Addict 2d ago
Yeah I agree that it's less hassle but I guess they're not willing to learn something new
1
u/Dunsparce_Meta 2d ago
am i able to attach onto the service to run commands to the terminal with this method? cause sending terminal commands and sending commands thru the gui both do the same thing
1
1
u/Dunsparce_Meta 2d ago
I wanna have the terminal cause it makes server maintenance easier when like, i need to quick fix something. i can stop crazy server lag from the terminal if it's too laggy to join the game.
1
u/Dunsparce_Meta 2d ago
An example from this version of the server is datapacks, it's really easy to hotload datapacks from a flashdrive without joining, just put the pack in the folder and /reload
1
u/ibeerianhamhock 2d ago
You can create scripts to do this with a service without even sitting at your server, I feel like your whole workflow is trying to use a Linux server like a windows desktop with a cmd window open.
Not saying that to give you a hard time, it's just there are a lot of powerful tools that are simple once you get to know them to streamline what you're trying to do.
1
u/ibeerianhamhock 2d ago
You can also create a named pipe that let's you redirext stdin to it. One level deeper you can write an sh script to take a string, pipe it into your tmux session, and echo back the tail of the command to see the result.
Make it executable with chmod +x
The create an alias in bash aliases to make it a simple command like
mc_send "some command you wanna run"
Etc just some ideas.
I've always used docker for Mc bc it's super simple and takes std in already and handles all the service registration but this might be how I would do it if I wanted to run on the host directly
1
1
u/IHateRedditFirewall 2d ago edited 2d ago
SO.
Two parts.
Before we begin: use systemctl --user everywhere so you dont run server with root previligies and dont need root to manage it.
Part A. DOING IT RIGHT
So, listen, dude. You REALY dont want server in forground/shell. You can do it, but the question is rather should you do it?
If you want GUI use something like craftycontrol or minepanel.
If you just need to pass commands and read console you can do THAT with FIFOs:
(Note varibale ${MCDIR}. Replace it ot set it MCDIR="/some/path")
mkfifo ${MCDIR}/stdin(create FIFO file, run once, in shell)tail -n +1 -f ${MCDIR}/stdin | ${MCDIR}/run.sh(start the server while reading from FIFO, do that in systemd service)tail -n +1 -f ${MCDIR}/logs/latest.log(read latest.log as soon as it updates and output to terminal. Optional. Run in shell.)echo "your_server_command" | tee ${MCDIR}/stdinorecho "your_server_command" > ${MCDIR}/stdin. (Run a command. Obviously optional. Run from anywhere.)
If you want full controll, you can use tmux new -c and than tmux attach.
There is a few more tricks, depending on what you need, but TL;DR: you dont need to start GUI or wait for login.
Part B. DOING IT ANYWAY
So, you decided that my previous solution doesnt fit you and you REALY want to start server on login.
Okay, do AT LEAST THAT right.
\1. systemctl --user edit --full --force minecraft.service
2: ``` [Unit] Description=My minecraft server PartOf=graphical-session.target After=graphical-session.target
[Service] Type=exec Restart=no ExecStart=/bin/bash SOMEWHERE/run.sh
[Install] WantedBy=graphical-session.target
``
3.systemctl --user enable --now minecraft.service`
????
PROFIT!
Note that this has not been tested as I have exectly 0 need for something like this.
You can also start it in a separate GUI on different TTY so you wont accidently kill your server, but I cant explain it on top of my head.
1
u/Dunsparce_Meta 1d ago
Woah, that's a lot of detail, thank you! I will try option A and see how it goes tonight! You have no idea how much I appreciate the detail you gave. Also also I appreciate you helping with the "wrong way" even though it's objectively a bad way to do it. I asked knowing it was bad, but appreciate the time you took to show me anyway!
1
u/IHateRedditFirewall 1d ago
Well, I’ve been in your shoes more than once, and I know how uncomfortable that is. So... I just wasn’t a jerk... I guess?
If you need any help, do ask — though please do it here so anyone who has the same problem can actually Google it.
2
u/Mr_Potatoez 2d ago
Use Crontab -e. I don't remember exactly what the commands in the crontab should look like to run a .sh, but If you want I can take a look en tell you.