-
Notifications
You must be signed in to change notification settings - Fork 61
/
minecraft-server.yaml
58 lines (55 loc) · 1.94 KB
/
minecraft-server.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Minecraft Server on AWS EC2'
Resources:
MinecraftSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: 'Enable SSH and Minecraft server port'
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 25565
ToPort: 25565
CidrIp: 0.0.0.0/0
MinecraftServer:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: t4g.small
ImageId: ami-02cd6549baea35b55
KeyName: Minecraft Server
SecurityGroups:
- Ref: MinecraftSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
wget https://download.oracle.com/java/17/latest/jdk-17_linux-aarch64_bin.tar.gz
sudo tar xvf jdk-17_linux-aarch64_bin.tar.gz -C /opt
wget https://piston-data.mojang.com/v1/objects/8dd1a28015f51b1803213892b50b7b4fc76e594d/server.jar -O minecraft_server.jar
echo 'eula=true' > eula.txt
export JAVA_HOME=$(find /opt -type d -name "jdk*" -print -quit)
echo 'export JAVA_HOME='$JAVA_HOME >> ~/.bashrc
source ~/.bashrc
cat <<EOF > /etc/systemd/system/minecraft.service
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=root
Nice=5
KillMode=none
SuccessExitStatus=0 1
InaccessibleDirectories=/root /sys /srv /media -/lost+found
NoNewPrivileges=true
WorkingDirectory=/
ExecStart=$JAVA_HOME/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable minecraft.service
systemctl start minecraft.service