Last active
January 28, 2019 20:02
-
-
Save nathangoulding/6a69b3fd7023bf3f558acfc7bb9ba645 to your computer and use it in GitHub Desktop.
delete-on-shutdown.sh
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
#!/bin/sh | |
cat <<EOF > /lib/systemd/system/delete-on-shutdown.service | |
[Unit] | |
Description=Delete this instance | |
Requires=network.target | |
DefaultDependencies=no | |
Before=shutdown.target | |
[Service] | |
Type=oneshot | |
RemainAfterExit=true | |
ExecStart=/bin/true | |
ExecStop=/usr/bin/curl -X DELETE -H "X-Auth-Token: ${API_TOKEN}" "https://api.packet.net/devices/$(curl https://metadata.packet.net/metadata 2>/dev/null | jq -r '.id')" | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
chmod +x /lib/systemd/system/delete-on-shutdown.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment