Skip to main content

Shut Down Instance with In-Instance Command

During training or inference, if you are not sure how long your code will take to finish, but you want the instance to shut down immediately after the training or inference completes in order to save costs, you can achieve this with the /usr/local/bin/poweroff command.


1. Download the poweroff command to the instance

Download poweroff command
curl -sSL -o /usr/local/bin/poweroff https://oss-high-qy01.cdsgss.com/public-static-prod-gpuzoom/installation/tools/poweroff
chmod +x /usr/local/bin/poweroff

2. Call the poweroff command after code execution to shut down the instance

Please save your program logs. After the automatic shutdown, logs in standard output will no longer be visible.

# Suppose your original command was:
python train.py

# You can append the poweroff command after your program:
python train.py; /usr/local/bin/poweroff # Using ; means the poweroff command runs regardless of success or failure of the previous command
python train.py && /usr/local/bin/poweroff # Using && means the poweroff command runs only if the previous command succeeds. Choose according to your needs.

3. Embed the poweroff command in your code

import os

if __name__ == "__main__":
# xxxxxx
os.system("/usr/local/bin/poweroff")