Created
September 4, 2020 20:53
-
-
Save tevaum/64d45b8488010a8c572a54edc989cf50 to your computer and use it in GitHub Desktop.
This file contains 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 | |
AUTH_KEY=YOUR_API_KEY_HERE | |
function rancher-service-get-id () { | |
env="$1" | |
service="$2" | |
if [ -z "$service" ]; then | |
echo use rancher-service-get-id '<environment id> <service name>' | |
return | |
fi | |
curl -s -u "$AUTH_KEY" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' https://rancher2.dds.ufvjm.edu.br/v2-beta/projects/$env/services?name=$service | jq .data[0].id | tr -d '"' | |
} | |
function rancher-service-restart () { | |
env="$1" | |
service="$2" | |
if [ -z "$service" ]; then | |
echo use rancher-service-restart '<environment id> <service name>' | |
return | |
fi | |
service_id=$(rancher-service-get-id $env $service) | |
curl -s -u "$AUTH_KEY" -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"rollingRestartStrategy":""}' https://rancher2.dds.ufvjm.edu.br/v2-beta/projects/$env/services/$service_id/?action=restart | |
} | |
rancher-service-restart "$1" "$2" | |
# Given an environment with ID 719a and a service called webserver in a stack called streamer | |
# you will restart the webserver like this: | |
# rancher-restart-service.sh 719a streamer/webserver | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment