Get a Discord alert when a Crafty Controller server crashes
Crafty's webhooks announce start-ups and shut-downs. Add crash alerts in Discord with a free port-check script, or with MineOps beside Crafty: crash loops, disk, memory and backups, and restarts after a crash.
Crafty Controller's webhooks can post to Discord when a server starts up or shuts down. If you also want to hear when a server crashes in the night, there are two ways: a short script you run yourself, or MineOps watching the servers beside Crafty.
The free way: a port check every minute
On the machine that runs Crafty, a cron job can check each server's port and post to a Discord webhook when it stops answering. You need curl and nc (on Debian or Ubuntu, sudo apt install netcat-openbsd) and a webhook from the Discord channel's Integrations settings.
- Save this as
~/mc-check.sh, put in your webhook and the port the server listens on, and runchmod +x ~/mc-check.sh. - Run
crontab -eand add* * * * * $HOME/mc-check.sh. - Stop the server in Crafty, wait a minute and check that the message arrives. Start it again for the all-clear.
#!/usr/bin/env bash
# Posts to Discord when the Minecraft server stops answering, and again when it's back.
HOST=127.0.0.1
PORT=25565
WEBHOOK="https://discord.com/api/webhooks/your-id/your-token"
STATE="$HOME/.mc-check-down"
send() {
curl -s -H "Content-Type: application/json" -d "{\"content\":\"$1\"}" "$WEBHOOK" >/dev/null
}
if nc -z -w 5 "$HOST" "$PORT" 2>/dev/null; then
if [ -f "$STATE" ]; then rm -f "$STATE"; send "Minecraft server is back up"; fi
else
if [ ! -f "$STATE" ]; then touch "$STATE"; send "Minecraft server is down"; fi
fiThe state file means one message when the server goes down and one when it comes back, not one a minute. For a second server, copy the script with its own port and state file.
What a port check misses
- It can't tell a crash from a stop you made in Crafty, so planned stops send an alert too.
- A server that has frozen but still holds its port looks healthy, and a crash loop that comes back within the minute can go unnoticed.
- It says nothing about low disk space, memory, lag or a backup that failed.
The MineOps way
MineOps runs a small agent on the same machine. Its installer finds Crafty running in Docker and connects it, and Crafty keeps running your servers. What the Crafty connection needs and does.
- Install the agent with one command. It only connects outward, so there are no ports to open.
- Paste your Discord or Slack webhook into Alerts → Where alerts go.
- Choose the alerts: a server offline or crash-looping, low memory or disk, a failed backup, and the message when it recovers.
A stop you make through MineOps, or during a maintenance window, counts as planned rather than as an outage. On Plus and up, a crash-restart policy on the server's Automation tab starts a crashed server again, a limited number of times so a crash loop doesn't restart forever.
Questions
Does it work with Crafty installed without Docker?
Not yet. MineOps connects Crafty running in Docker on Linux, in a container named crafty. The port-check script works with any install.
What does it cost?
Two Minecraft servers on one machine are free. Crash restarts, backups and more servers come with the paid plans. See the plans.