|
6 | 6 | CURR_DIR = os.path.dirname(os.path.realpath(__file__)) |
7 | 7 |
|
8 | 8 | # Add EC2-specific units to the shared user-data |
9 | | -FORMAT_EPHEMERAL = ''' |
| 9 | +FORMAT_EPHEMERAL_VOLUME = ''' |
10 | 10 | [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 |
12 | 45 | ConditionPathExists=!/etc/docker-volume-formatted |
13 | 46 | [Service] |
14 | 47 | Type=oneshot |
|
17 | 50 | ExecStart=/usr/sbin/mkfs.btrfs -f /dev/xvdf |
18 | 51 | ExecStart=/bin/touch /etc/docker-volume-formatted |
19 | 52 | ''' |
20 | | -DOCKER_MOUNT = ''' |
| 53 | +MOUNT_DOCKER_VOLUME = ''' |
21 | 54 | [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 |
25 | 58 | Before=docker.service |
26 | 59 | [Mount] |
27 | 60 | What=/dev/xvdf |
|
30 | 63 | ''' |
31 | 64 |
|
32 | 65 | 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' |
35 | 74 |
|
36 | 75 | header = ["#cloud-config", "---"] |
37 | 76 | dump = yaml.dump(data, default_flow_style=False) |
|
0 commit comments