-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminecraft.yml
More file actions
192 lines (191 loc) · 5.7 KB
/
minecraft.yml
File metadata and controls
192 lines (191 loc) · 5.7 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Deploy Minecraft server running Spigot'
Parameters:
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: must be the name of an existing EC2 KeyPair.
InstanceType:
Description: Minecraft Server EC2 instance type
Type: String
Default: t2.medium
AllowedValues:
- t2.micro
- t2.medium
- t3a.medium
ConstraintDescription: must be a valid EC2 instance type.
ManagementLocation:
Description: The IP address range that can be used to SSH manage the EC2 instances
Type: String
MinLength: '9'
MaxLength: '18'
Default: 0.0.0.0/0
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
GameServerLocation:
Description: The IP address range that can be used to connect to Minecraft
Type: String
MinLength: '9'
MaxLength: '18'
Default: 0.0.0.0/0
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
Mappings:
AWSInstanceType2Arch:
t2.micro:
Arch: HVM64
t2.medium:
Arch: HVM64
t3a.medium:
Arch: HVM64
AWSInstanceType2NATArch:
t2.micro:
Arch: NATHVM64
t2.medium:
Arch: NATHVM64
t3a.medium:
Arch: NATHVM64
AWSRegionArch2AMI:
us-east-1:
HVM64: ami-07ebfd5b3428b6f4d
Resources:
MinecraftEC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType:
Ref: InstanceType
SecurityGroups:
- Ref: MinecraftInstanceSecurityGroup
KeyName:
Ref: KeyName
Tags:
-
Key: "Name"
Value: !Join
- ''
- - 'Minecraft_'
- !Ref AWS::StackName
ImageId:
Fn::FindInMap:
- AWSRegionArch2AMI
- Ref: AWS::Region
- Fn::FindInMap:
- AWSInstanceType2Arch
- Ref: InstanceType
- Arch
UserData: !Base64
'Fn::Join':
- ''
- - |
#!/bin/bash
- |
# set envs
- |
echo "export HOME=/root" >> /etc/profile
- |
echo "export HOME=/root" >> /etc/environment
- |
source /etc/profile
- |
source /etc/environment
- |
# Update system
- |
apt update
- |
DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
- |
DEBIAN_FRONTEND=noninteractive apt install -y git curl
- |
DEBIAN_FRONTEND=noninteractive apt install -y openjdk-8-jre-headless git curl screen python-pip
- |
pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
- |
chmod -x /etc/update-motd.d/*
- |
cat <<EOT > /etc/update-motd.d/01-minecraft
- |
#!/bin/sh
- |
#
- |
HOSTNAME=$(curl -s http://169.254.169.254/latest/meta-data/public-hostname)
- |
printf "Minecraft Server running on $HOSTNAME port 25565 \n\n"
- |
EOT
- |
chmod +x /etc/update-motd.d/01-minecraft
- |
mkdir /minecraft
- |
curl -o /minecraft/BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
- |
git config --system --unset core.autocrlf
- |
cd /minecraft
- |
java -jar -Xmx1024M /minecraft/BuildTools.jar --rev latest
- |
cat <<EOT > /minecraft/background.sh
- |
#!/bin/sh
- |
screen -d -m -S "minecraft" java -jar /minecraft/spigot*.jar -nogui
- |
EOT
- |
cat <<EOT > /minecraft/eula.txt
- |
#By changing the setting below to TRUE you are indicating your agreement to our EULA
- |
#Mon Feb 25 02:34:11 UTC 2019
- |
eula=true
- |
EOT
- |
chmod +x /minecraft/background.sh
- |
/minecraft/background.sh
- |
# do further config on your own, like plugins, operators, server motd, etc
- |+
- |
# Signal the status from cfn-init
- '/usr/local/bin/cfn-signal -e $? '
- ' --stack '
- !Ref 'AWS::StackName'
- ' --resource MinecraftEC2Instance '
- ' --region '
- !Ref 'AWS::Region'
- |+
CreationPolicy:
ResourceSignal:
Timeout: PT15M
MinecraftInstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable Access for Minecraft Server
SecurityGroupIngress:
- IpProtocol: '-1'
CidrIp:
Ref: ManagementLocation
- IpProtocol: tcp
FromPort: '25565'
ToPort: '25565'
CidrIp:
Ref: GameServerLocation
Outputs:
PublicDNS:
Description: Public DNSName of the newly created EC2 instance
Value:
Fn::GetAtt:
- MinecraftEC2Instance
- PublicDnsName
PublicIP:
Description: Public IP address of the newly created EC2 instance
Value:
Fn::GetAtt:
- MinecraftEC2Instance
- PublicIp