Created
July 5, 2016 22:56
-
-
Save ivanalejandro0/89bb434bddacf714f6c90a133290c3ee to your computer and use it in GitHub Desktop.
Swap service for CoreOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/systemd/system/swapon.service | |
# from: https://www.matthowlett.com/notes/2015/08/01/coreos-swap.html | |
# sudo systemctl enable swapon.service | |
# restart | |
# or | |
# sudo systemctl start swapon | |
[Unit] | |
Description=Turn on swap | |
[Service] | |
Type=oneshot | |
Environment="SWAPFILE=/1024MiB.swap" | |
RemainAfterExit=true | |
ExecStartPre=/usr/bin/touch ${SWAPFILE} | |
ExecStartPre=/usr/bin/chattr +C ${SWAPFILE} | |
ExecStartPre=/usr/bin/fallocate -l 1024m ${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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment