Created
November 26, 2019 15:32
-
-
Save adowning/fd0ccd69d2d4b7ac65e55491f585883d to your computer and use it in GitHub Desktop.
gcp shutdown
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/bash | |
| MY_PROGRAM="stelace-core" # For example, "apache2" or "nginx" | |
| MY_USER="ubuntu" | |
| CHECKPOINT="/home/$MY_USER/checkpoint.out" | |
| GSUTIL_OPTS="-m -o GSUtil:parallel_composite_upload_threshold=32M" | |
| BUCKET_NAME="my-checkpoint-files" # For example, "my-checkpoint-files" (without gs://) | |
| echo "Shutting down! Seeing if ${MY_PROGRAM} is running." | |
| # Find the newest copy of $MY_PROGRAM | |
| PID="$(pgrep -n "$MY_PROGRAM")" | |
| if [[ "$?" -ne 0 ]]; then | |
| echo "${MY_PROGRAM} not running, shutting down immediately." | |
| exit 0 | |
| fi | |
| echo "Sending SIGINT to $PID" | |
| kill -2 "$PID" | |
| # Portable waitpid equivalent | |
| while kill -0 "$PID"; do | |
| sleep 1 | |
| done | |
| echo "$PID is done, copying ${CHECKPOINT} to gs://${BUCKET_NAME} as ${MY_USER}" | |
| su "${MY_USER}" -c "gsutil $GSUTIL_OPTS cp $CHECKPOINT gs://${BUCKET_NAME}/" | |
| echo "Done uploading, shutting down." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment