By nicbarker
Hi guys, Huge fan of DO - been using it for a few years now on heaps of different projects. One thing I’ve noticed myself doing repeatedly on almost every small (i.e 20gb) droplet that I spin up is creating a gig or so of swap space.
Seeing as this is such a common thing to do for a lot of use cases (i.e running passenger or unicorn on a 512mb ram droplet) would you consider adding an option to the “create droplet” wizard that allows you to automatically create / turn on swap of a certain size?
Cheers, Nic
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
If you are creating a droplet using the digitalocean docker-machine driver, put this unit in your cloud-config file (the one you provide to the --digitalocean-userdata parameter)
units:
- name: runcmd.service
command: start
content: |
[Unit]
Description=Enable swap
[Service]
Type=oneshot
ExecStart=/bin/sh -c "\
sudo fallocate -l 4G /swapfile && \
sudo chmod 600 /swapfile && \
sudo mkswap /swapfile && \
sudo swapon /swapfile && \
sudo echo "/swapfile none swap sw 0 0" | sudo tee --append /etc/fstab"
We do have this feature on some one-click applications (where a swap file is automatically created on smaller droplets) and some distributions like FreeBSD include a swap partition by default. You can add a swap file at creation by using the following script in user-data on the create page:
#!/bin/bash
sudo fallocate -l 1G /swapfile;
chmod 600 /swapfile;
mkswap /swapfile;
swapon /swapfile;
echo "/swapfile none swap sw 0 0" >> /etc/fstab;
This will create a 1GB swap file as soon as your droplet boots for the first time and add it to your fstab to be automatically used on each subsequent boot.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.