Skip to content

Instantly share code, notes, and snippets.

@nathangoulding
Last active January 28, 2019 20:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathangoulding/6a69b3fd7023bf3f558acfc7bb9ba645 to your computer and use it in GitHub Desktop.
Save nathangoulding/6a69b3fd7023bf3f558acfc7bb9ba645 to your computer and use it in GitHub Desktop.
delete-on-shutdown.sh
#!/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