-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage-pods.sh
executable file
·31 lines (27 loc) · 1.34 KB
/
manage-pods.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
operation=$1
apiKey=$2
huggingFaceToken=$3
## START ##
if [ $operation = "--start" ]
then
## Start a pod with NVIDIA RTX A4000 GPU
curl --request POST \
--header 'content-type: application/json' \
--url 'https://api.runpod.io/graphql?api_key='$apiKey'' \
--data '{"query": "mutation { podFindAndDeployOnDemand( input: { cloudType: ALL, gpuCount: 1, volumeInGb: 5, containerDiskInGb: 5, minVcpuCount: 2, minMemoryInGb: 15, gpuTypeId: \"NVIDIA RTX A4000\", name: \"RunPod PyTorch\", imageName: \"runpod/pytorch\", dockerArgs: \"bash -c \\\"wget -O - https://raw.githubusercontent.com/novoda/dreams/main/pod-start-command.sh | bash\\\"\", ports: \"8888/http\", volumeMountPath: \"/workspace\", env: [{ key: \"HUGGING_FACE\", value: \"'$huggingFaceToken'\" }] } ) { id imageName env machineId machine { podHostId } } }"}'
fi
## STOP ##
if [ $operation = "--stop" ]
then
## Finds running Pod
id=$(curl --request POST \
--header 'content-type: application/json' \
--url 'https://api.runpod.io/graphql?api_key='$apiKey'' \
--data '{"query": "query Pods { myself { pods { id } } }"}' | jq -r '.data.myself.pods[0].id')
## Terminates running Pod
curl --request POST \
--header 'content-type: application/json' \
--url 'https://api.runpod.io/graphql?api_key='$apiKey'' \
--data '{"query": "mutation { podTerminate( input: { podId: \"'$id'\" } ) }"}'
fi