Score:0

How to restart a modded Minecraft server every 24 hours?

bo flag

I made a .SH file that looks like this:

Letting people know that the server is going to restart:

tmux send-keys -t VHS "/say §cServer restarting in §l30 minutes. §rPlease get ready to log off." Enter

# Wait for 1770 seconds (29 minutes and 30 seconds)
sleep 1770s

Send messages to the server indicating the restart countdown:

tmux send-keys -t VHS "/say §cServer is restarting in §l30 seconds! §rthe restart will take aproximately 5 minutes!" Enter
sleep 20s

tmux send-keys -t VHS "/say §cServer is restarting in §l10 seconds!" Enter
sleep 5s

tmux send-keys -t VHS "/say §cServer is restarting in §l5 seconds!" Enter
sleep 1s

tmux send-keys -t VHS "/say §cServer is restarting in §l4 seconds!" Enter
sleep 1s

tmux send-keys -t VHS "/say §cServer is restarting in §l3 seconds!" Enter
sleep 1s

tmux send-keys -t VHS "/say §cServer is restarting in §l2 seconds!" Enter
sleep 1s

tmux send-keys -t VHS "/say §cServer is restarting in §l1 second!" Enter
sleep 1s

Stop the Minecraft server:

tmux send-keys -t VHS "/stop" Enter
sleep 300s

Restart the server using the run.sh script:

tmux send-keys -t VHS "./run.sh" Enter

And the line of code I have made for the crontab looks like this:

0 21 * * * /VHServer/restart.sh

The .sh file seems to run everything but the /stop command and possibly the ./run.sh I have set up for the server, can I please get an explanation why?

Raffa avatar
jp flag
`./run.sh` is a path relative to your current working directory that might not be the same working directory for `cron` ... So what seems obvious to you isn't necessarily obvious to `cron` ... You need to provide the full path instead like for example `/home/username/run.sh`.
PerplexApple avatar
bo flag
Thankyou, so if I understand this correctly I need to add another line to the Cron job that executes the ru.sh file directly rather than through the restart.sh. if that's the case I will need to edit the run.sh file to open up a tmux session or send that command into the tmux session correct?
Raffa avatar
jp flag
You're welcome ... No, just change `tmux send-keys -t VHS "./run.sh" Enter` to something like `tmux send-keys -t VHS "/home/username/run.sh" Enter` i.e. the full path to the `run.sh` script inside `/VHServer/restart.sh`
PerplexApple avatar
bo flag
all seems to work now! thanks!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.