Skip to content

Commit eca08d8

Browse files
committed
Merge pull request #2850 from carmstrong/ec2-mount_ephemeral
feat(contrib/ec2): use ephemeral drive for etcd journal
2 parents e27dbc8 + 73f2eda commit eca08d8

1 file changed

Lines changed: 47 additions & 8 deletions

File tree

contrib/ec2/gen-json.py

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,42 @@
66
CURR_DIR = os.path.dirname(os.path.realpath(__file__))
77

88
# Add EC2-specific units to the shared user-data
9-
FORMAT_EPHEMERAL = '''
9+
FORMAT_EPHEMERAL_VOLUME = '''
1010
[Unit]
11-
Description=Formats the ephemeral drive
11+
Description=Formats the ephemeral volume
12+
ConditionPathExists=!/etc/ephemeral-volume-formatted
13+
[Service]
14+
Type=oneshot
15+
RemainAfterExit=yes
16+
ExecStart=/usr/sbin/wipefs -f /dev/xvdb
17+
ExecStart=/usr/sbin/mkfs.ext4 /dev/xvdb
18+
ExecStart=/bin/touch /etc/ephemeral-volume-formatted
19+
'''
20+
MOUNT_EPHEMERAL_VOLUME = '''
21+
[Unit]
22+
Description=Formats and mounts the ephemeral drive
23+
Requires=format-ephemeral-volume.service
24+
After=format-ephemeral-volume.service
25+
[Mount]
26+
What=/dev/xvdb
27+
Where=/media/ephemeral
28+
Type=ext4
29+
'''
30+
PREPARE_ETCD_DATA_DIRECTORY = '''
31+
[Unit]
32+
Description=Prepares the etcd data directory
33+
Requires=media-ephemeral.mount
34+
After=media-ephemeral.mount
35+
Before=etcd.service
36+
[Service]
37+
Type=oneshot
38+
RemainAfterExit=yes
39+
ExecStart=/usr/bin/mkdir -p /media/ephemeral/etcd
40+
ExecStart=/usr/bin/chown -R etcd /media/ephemeral/etcd
41+
'''
42+
FORMAT_DOCKER_VOLUME = '''
43+
[Unit]
44+
Description=Formats the added EBS volume for Docker
1245
ConditionPathExists=!/etc/docker-volume-formatted
1346
[Service]
1447
Type=oneshot
@@ -17,11 +50,11 @@
1750
ExecStart=/usr/sbin/mkfs.btrfs -f /dev/xvdf
1851
ExecStart=/bin/touch /etc/docker-volume-formatted
1952
'''
20-
DOCKER_MOUNT = '''
53+
MOUNT_DOCKER_VOLUME = '''
2154
[Unit]
22-
Description=Mount ephemeral to /var/lib/docker
23-
Requires=format-ephemeral.service
24-
After=format-ephemeral.service
55+
Description=Mount Docker volume to /var/lib/docker
56+
Requires=format-docker-volume.service
57+
After=format-docker-volume.service
2558
Before=docker.service
2659
[Mount]
2760
What=/dev/xvdf
@@ -30,8 +63,14 @@
3063
'''
3164

3265
data = yaml.load(file(os.path.join(CURR_DIR, '..', 'coreos', 'user-data'), 'r'))
33-
data['coreos']['units'].append(dict({'name': 'format-ephemeral.service', 'command': 'start', 'content': FORMAT_EPHEMERAL}))
34-
data['coreos']['units'].append(dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': DOCKER_MOUNT}))
66+
data['coreos']['units'].append(dict({'name': 'format-ephemeral-volume.service', 'command': 'start', 'content': FORMAT_EPHEMERAL_VOLUME}))
67+
data['coreos']['units'].append(dict({'name': 'media-ephemeral.mount', 'command': 'start', 'content': MOUNT_EPHEMERAL_VOLUME}))
68+
data['coreos']['units'].append(dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}))
69+
data['coreos']['units'].append(dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}))
70+
data['coreos']['units'].append(dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}))
71+
72+
# configure etcd to use the ephemeral drive
73+
data['coreos']['etcd']['data-dir'] = '/media/ephemeral/etcd'
3574

3675
header = ["#cloud-config", "---"]
3776
dump = yaml.dump(data, default_flow_style=False)

0 commit comments

Comments
 (0)