Created
March 14, 2018 02:28
-
-
Save edco/7d39aef3fe57caeb4cd9752c2b46c1d2 to your computer and use it in GitHub Desktop.
Create a Minecraft server on Google Cloud Platform in moments. Running this script amounts to accepting the Minecraft EULA. Based on https://cloud.google.com/solutions/gaming/minecraft-server but without the dedicated storage and backups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources: | |
- type: compute.v1.address | |
name: mcs-ip | |
properties: | |
region: australia-southeast1 | |
- type: compute.v1.instance | |
name: mc-server | |
properties: | |
zone: australia-southeast1-c | |
machineType: zones/australia-southeast1-c/machineTypes/n1-standard-1 | |
disks: | |
- type: PERSISTENT | |
deviceName: mc-server | |
boot: true | |
autoDelete: true | |
initializeParams: | |
sourceImage: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts | |
diskType: zones/australia-southeast1-c/diskTypes/pd-ssd | |
networkInterfaces: | |
- network: global/networks/default | |
accessConfigs: | |
- name: External NAT | |
type: ONE_TO_ONE_NAT | |
natIP: $(ref.mcs-ip.address) | |
tags: | |
items: | |
- minecraft-server | |
scheduling: | |
preemptible: true | |
metadata: | |
items: | |
- key: startup-script | |
value: | | |
if [ ! -d /home/minecraft ] ; then | |
apt-get update | |
apt-get dist-upgrade -y | |
apt-get install -y default-jre-headless screen | |
echo alias mcc=\"sudo su -s /bin/sh minecraft -c \'script -q -c \\\"screen -r\\\" /dev/null\'\" >> /etc/bash.bashrc | |
echo Welcome to Ed\'s quick\'n\'dodgy Minecraft server! > /etc/motd | |
echo Use the \'mcc\' command to connect to the console, and \'Ctrl+A d\' to disconnect again. >> /etc/motd | |
echo >> /etc/motd | |
adduser --system minecraft | |
cd /home/minecraft | |
sudo -u minecraft -H sh -c " | |
curl -sSO https://s3.amazonaws.com/Minecraft.Download/versions/1.12.2/minecraft_server.1.12.2.jar | |
java -Xms1G -Xmx7G -d64 -jar minecraft_server.1.12.2.jar nogui | |
sed -i 's/eula=false/eula=true/' eula.txt | |
sed -i 's/white-list=false/white-list=true/' server.properties | |
cat << 'EOF' >> whitelist.json | |
[ | |
{ | |
\"uuid\": \"069a79f4-44e9-4726-a5be-fca90e38aaf5\", | |
\"name\": \"Notch\" | |
} | |
] | |
EOF" | |
fi | |
cd /home/minecraft | |
sudo -u minecraft -H screen -d -m -S mcs java -Xms1G -Xmx7G -d64 -jar minecraft_server.1.12.2.jar nogui | |
- key: shutdown-script | |
value: | | |
#!/bin/bash | |
sudo -u minecraft -H screen -r -X stuff '/stop\n' | |
- type: compute.v1.firewall | |
name: minecraft-rule | |
properties: | |
allowed: | |
- IPProtocol: tcp | |
ports: | |
- '25565' | |
direction: INGRESS | |
network: global/networks/default | |
sourceRanges: | |
- 0.0.0.0/0 | |
targetTags: | |
- minecraft-server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gcloud services enable compute.googleapis.com
gcloud services enable deploymentmanager.googleapis.com
gcloud deployment-manager deployments create minecraft --config=mc-server.yaml