Skip to content

Instantly share code, notes, and snippets.

@Adam-Clrk
Last active February 6, 2024 20:12
Show Gist options
  • Save Adam-Clrk/e5beab9062e7ed7456b2bfeda5c8d7f0 to your computer and use it in GitHub Desktop.
Save Adam-Clrk/e5beab9062e7ed7456b2bfeda5c8d7f0 to your computer and use it in GitHub Desktop.
Minecraft server cloud-init
#cloud-config
users:
- default
- name: minecraft
ssh_import_id: gh:adam-clrk
gecos: Minecraft server user
lock_passwd: true
#sudo: ALL=(ALL) NOPASSWD:ALL
package_update: true
package_upgrade: true
packages:
# - default-jre
- git
- openjdk-8-jre-headless
- screen
write_files:
- path: "/etc/fstab"
content: "LABEL=swap1\t/mnt/2GB.swap\tnoneztswap\tsw\t0\t0"
append: true
- path: "/etc/sysctl.conf"
content: "vm.swappiness=60"
append: true
- path: "/etc/systemd/system/minecraft-server.service"
content: |
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=minecraft
Group=minecraft
WorkingDirectory=/home/minecraft/server1
ExecStart=/usr/bin/screen -DmS minecraft /home/minecraft/server1/start.sh
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "save-all"\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "stop"\015'
[Install]
WantedBy=multi-user.target
- path: /home/minecraft/spigot/setup.sh
permissions: '0774'
content: |
git config --global --unset core.autocrlf
cd "${0%/*}"
mkdir ../server1
java -Xmx512M -jar BuildTools.jar -o ../server1
cd ../server1
echo eula=true >eula.txt
mkdir plugins
cd plugins
wget https://media.forgecdn.net/files/2745/835/Multiverse-Inventories-3.0.0.jar
wget https://media.forgecdn.net/files/2768/599/Multiverse-Core-4.1.0.jar
wget https://media.forgecdn.net/files/2768/603/Multiverse-SignPortals-4.1.0.jar
- path: /home/minecraft/server1/start.sh
content: |
#!/bin/bash
cd "${0%/*}"
java -Xmx2G -jar spigot-*.jar
runcmd:
- fallocate -l 2G /mnt/2GB.swap
- mkswap /mnt/2GB.swap
- chmod 0600 /mnt/2GB.swap
- swapon /mnt/2GB.swap
- mkdir /home/minecraft/spigot/
- wget 'https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar' -O /home/minecraft/spigot/BuildTools.jar
- chown -R minecraft:minecraft /home/minecraft
- sudo -Hu minecraft /home/minecraft/spigot/setup.sh
- chmod +x /home/minecraft/server1/start.sh
- rm /root/.ssh/authorized_keys
- ssh-import-id gh:adam-clrk
  • update and upgrade,
  • install Java, git, screen
  • creates setup, start and systemd scripts
  • sets up 2GB swap file and makes swappiness 60
  • download and run Spigot BuildTools

tested on ubuntu Ubuntu 18.04.3 (LTS) on DigitalOcean

setup logs:

tail -f /var/log/cloud-init.log

tail -f /var/log/cloud-init-output.log

start server

systemctl start minecraft-server

server config

sudo -Hu minecraft nano /home/minecraft/server1/server.properties

open server console

sudo -u minecraft screen -r
@DominicFaught
Copy link

thanks Adam!!!!!! 💞💞💓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment