|
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_VOLUME = ''' |
10 | | - [Unit] |
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 -i 4096 -b 4096 /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:etcd /media/ephemeral/etcd |
41 | | -''' |
42 | 9 | FORMAT_DOCKER_VOLUME = ''' |
43 | 10 | [Unit] |
44 | 11 | Description=Formats the added EBS volume for Docker |
|
61 | 28 | Where=/var/lib/docker |
62 | 29 | Type=ext4 |
63 | 30 | ''' |
| 31 | +FORMAT_ETCD_VOLUME = ''' |
| 32 | + [Unit] |
| 33 | + Description=Formats the etcd device |
| 34 | + ConditionPathExists=!/etc/etcd-volume-formatted |
| 35 | + [Service] |
| 36 | + Type=oneshot |
| 37 | + RemainAfterExit=yes |
| 38 | + ExecStart=/usr/sbin/wipefs -f /dev/xvdg |
| 39 | + ExecStart=/usr/sbin/mkfs.ext4 -i 4096 -b 4096 /dev/xvdg |
| 40 | + ExecStart=/bin/touch /etc/etcd-volume-formatted |
| 41 | +''' |
| 42 | +MOUNT_ETCD_VOLUME = ''' |
| 43 | + [Unit] |
| 44 | + Description=Formats and mounts the ephemeral drive |
| 45 | + Requires=format-etcd-volume.service |
| 46 | + After=format-etcd-volume.service |
| 47 | + [Mount] |
| 48 | + What=/dev/xvdg |
| 49 | + Where=/media/etcd |
| 50 | + Type=ext4 |
| 51 | +''' |
| 52 | +PREPARE_ETCD_DATA_DIRECTORY = ''' |
| 53 | + [Unit] |
| 54 | + Description=Prepares the etcd data directory |
| 55 | + Requires=media-etcd.mount |
| 56 | + After=media-etcd.mount |
| 57 | + Before=etcd.service |
| 58 | + [Service] |
| 59 | + Type=oneshot |
| 60 | + RemainAfterExit=yes |
| 61 | + ExecStart=/usr/bin/chown -R etcd:etcd /media/etcd |
| 62 | +''' |
64 | 63 |
|
65 | 64 | new_units = [ |
66 | | - dict({'name': 'format-ephemeral-volume.service', 'command': 'start', 'content': FORMAT_EPHEMERAL_VOLUME}), |
67 | | - dict({'name': 'media-ephemeral.mount', 'command': 'start', 'content': MOUNT_EPHEMERAL_VOLUME}), |
68 | | - dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}), |
69 | 65 | dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}), |
70 | | - dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}) |
| 66 | + dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}), |
| 67 | + dict({'name': 'format-etcd-volume.service', 'command': 'start', 'content': FORMAT_ETCD_VOLUME}), |
| 68 | + dict({'name': 'media-etcd.mount', 'command': 'start', 'content': MOUNT_ETCD_VOLUME}), |
| 69 | + dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}) |
71 | 70 | ] |
72 | 71 |
|
73 | 72 | data = yaml.load(file(os.path.join(CURR_DIR, '..', 'coreos', 'user-data'), 'r')) |
|
76 | 75 | # are started |
77 | 76 | data['coreos']['units'] = new_units + data['coreos']['units'] |
78 | 77 |
|
79 | | -# configure etcd to use the ephemeral drive |
80 | | -data['coreos']['etcd']['data-dir'] = '/media/ephemeral/etcd' |
| 78 | +# configure etcd to use its EBS volume |
| 79 | +data['coreos']['etcd']['data-dir'] = '/media/etcd' |
81 | 80 |
|
82 | 81 | header = ["#cloud-config", "---"] |
83 | 82 | dump = yaml.dump(data, default_flow_style=False) |
|
0 commit comments