microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.72k stars 1.4k forks source link

Run command on stop/exit/remove codespace #1579

Open Pwd9000-ML opened 2 years ago

Pwd9000-ML commented 2 years ago

I have a clean-up script that I want to run when my codespace stops/is removed. I tried to capture the exit signal /SIGTERM, this does not work unfortunately. Is there a feature such as postStartCommand that can be used but when a codespace is stopped instead? Something like preStopCommand? This would be very handy, or please advise what sort of exit code to capture e.g.:

#cleanup.sh
cleanup() {
    echo "cleanup..."
    #<Command>
}

trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM

./cleanup.sh & wait $!

Relates to: <Codespaces | Remote - Containers | Both>

bamurtaugh commented 2 years ago

cc @joshspicer @edgonmsft @samruddhikhandale