Skip to content

Instantly share code, notes, and snippets.

@steigr
Last active August 1, 2018 14:51
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 steigr/cc4be305e06bc6c7e0b0dfac7a75b189 to your computer and use it in GitHub Desktop.
Save steigr/cc4be305e06bc6c7e0b0dfac7a75b189 to your computer and use it in GitHub Desktop.
# install via
# curl -sL https://gist.github.com/steigr/cc4be305e06bc6c7e0b0dfac7a75b189/raw/swapspace.service | install -D -m 0644 /dev/stdin /etc/systemd/system/swapspace.service && systemctl enable --now swapspace
[Service]
ExecStartPre=-/usr/bin/env mkdir -p /opt/bin /var/lib/swapspace
ExecStartPre=-/usr/bin/env swapoff /var/lib/swapspace/base.swap
ExecStartPre=-/usr/bin/env dd if=/dev/zero of=/var/lib/swapspace/base.swap bs=1M count=1
ExecStartPre=-/usr/bin/env chmod 0600 /var/lib/swapspace/base.swap
ExecStartPre=-/usr/bin/env mkswap /var/lib/swapspace/base.swap
ExecStartPre=-/usr/bin/env swapon /var/lib/swapspace/base.swap
ExecStartPre=/usr/bin/env bash -c 'test -s /opt/bin/swapspace || curl -sL https://github.com/mathias-kaufmann/swapspace/releases/download/1.10/swapspace | install -m 0744 /dev/stdin /opt/bin/swapspace'
ExecStart=/opt/bin/swapspace
ExecStopPost=/usr/bin/env bash -c 'swapon --show=NAME --noheadings | xargs -I{} bash -c "swapoff {} && rm {}"'
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment