Skip to content

Instantly share code, notes, and snippets.

@yebyen
Forked from romaninsh/swapon.service
Last active May 4, 2016 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yebyen/efb65e358807f2ad4b52 to your computer and use it in GitHub Desktop.
Save yebyen/efb65e358807f2ad4b52 to your computer and use it in GitHub Desktop.
Set up swap on CoreOS
create this file in your /root folder
$ fleetctl load swapon.service
$ fleetctl start swapon.service
This will create swap file on all nodes of your CoreOS cluster without prior setup.
See also http://cloudinit.readthedocs.org/en/latest/topics/examples.html#adjust-mount-points-mounted
Use an /etc/hosts file only if you understand the repercussions of doing that;
On my development machines, I just set up my `/etc/hosts` file like below, so I didn’t need to set up
any real DNS records or use a real domain name, use the content below:
```
1.0.192.192 deis deis.deis deis-1.deis
2.0.168.168 deis-2.deis
3.0.168.192 deis-3.deis
4.0.192.192 deis-4.deis
5.0.168.192 deis-5.deis
```
for one thing, your cluster would not be usable for any other client users on the internet at large.
[Unit]
Description=Turn on swap
[Service]
Type=oneshot
Environment="SWAPFILE=/4GiB.swap"
RemainAfterExit=true
ExecStartPre=/usr/bin/touch ${SWAPFILE}
ExecStartPre=/usr/bin/fallocate -l 4096m ${SWAPFILE}
ExecStartPre=/usr/bin/chmod 600 ${SWAPFILE}
ExecStartPre=/usr/sbin/mkswap ${SWAPFILE}
ExecStartPre=/usr/sbin/losetup -f ${SWAPFILE}
ExecStart=/usr/bin/sh -c "/sbin/swapon $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
ExecStop=/usr/bin/sh -c "/sbin/swapoff $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
ExecStopPost=/usr/bin/sh -c "/usr/sbin/losetup -d $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
[Install]
WantedBy=multi-user.target
[X-Fleet]
Global=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment