-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflex_minecraft_instance.yaml
148 lines (130 loc) · 4.53 KB
/
flex_minecraft_instance.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
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
heat_template_version: 2018-08-31
description: >
This Heat template provisions a virtual machine on OpenStack with a specified flavor, image, and SSH key, sets up a private network and subnet, configures routing to an external network, and installs a Minecraft Java server with the latest version. It includes security group rules to allow SSH and Minecraft server access, and assigns a floating IP to the instance for public accessibility.
parameters:
flavor:
type: string
description: Flavor of the instance
default: $FLAVOR_NAME
image:
type: string
description: Image to use for the instance
default: $IMAGE_ID
key_name:
type: string
description: Name of the SSH key to use
default: $KEY_NAME
public_net_id:
type: string
description: ID of the public network
default: $PUBLICNET_ID
resources:
private_net:
type: OS::Neutron::Net
properties:
name: private_net
private_subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: private_net }
cidr: "192.168.0.0/24"
gateway_ip: "192.168.0.1"
ip_version: 4
dns_nameservers:
- "8.8.8.8"
- "8.8.4.4"
router:
type: OS::Neutron::Router
properties:
name: router
external_gateway_info:
network: { get_param: public_net_id }
router_interface:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: router }
subnet_id: { get_resource: private_subnet }
instance_port:
type: OS::Neutron::Port
properties:
network_id: { get_resource: private_net }
security_groups: [{ get_resource: instance_security_group }]
instance_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: instance_security_group
description: Security group for the instance
rules:
- direction: ingress
ethertype: IPv4
protocol: tcp
port_range_min: 22
port_range_max: 22
- direction: ingress
ethertype: IPv4
protocol: icmp
- direction: ingress
ethertype: IPv4
protocol: tcp
port_range_min: 25565
port_range_max: 25565
floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { get_resource: instance_port }
instance:
type: OS::Nova::Server
properties:
flavor: { get_param: flavor }
image: { get_param: image }
key_name: { get_param: key_name }
networks:
- port: { get_resource: instance_port }
user_data:
str_replace:
template: |
#!/bin/bash
# Update and install necessary packages
apt-get update -y
apt-get install -y openjdk-17-jre-headless wget screen
# Create a new user for the Minecraft server
useradd -m -r -d /opt/minecraft minecraft
# Download the latest Minecraft server
su - minecraft -c "wget -O /opt/minecraft/minecraft_server.jar https://launcher.mojang.com/v1/objects/$(curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json | jq -r '.latest.release')/server.jar"
# Accept the EULA
echo "eula=true" > /opt/minecraft/eula.txt
# Create a systemd service for the Minecraft server
cat <<EOF > /etc/systemd/system/minecraft.service
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=minecraft
Nice=5
KillMode=none
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/opt/minecraft
ExecStart=/usr/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
ExecStop=/bin/kill -SIGINT \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd, enable and start the Minecraft service
systemctl daemon-reload
systemctl enable minecraft
systemctl start minecraft
params:
"$FLAVOR_NAME": { get_param: flavor }
"$IMAGE_ID": { get_param: image }
"$KEY_NAME": { get_param: key_name }
"$PUBLICNET_ID": { get_param: public_net_id }
outputs:
instance_ip:
description: IP address of the instance
value: { get_attr: [floating_ip, floating_ip_address] }