Skip to content

Instantly share code, notes, and snippets.

@tisseurdetoile
Created March 1, 2018 09:13
Show Gist options
  • Save tisseurdetoile/2e8bb146974eaaceae38994f81d9f418 to your computer and use it in GitHub Desktop.
Save tisseurdetoile/2e8bb146974eaaceae38994f81d9f418 to your computer and use it in GitHub Desktop.
RancherScript - A script that remove the service associated to his container.
#!/bin/bash
ranchermeta=http://rancher-metadata/latest/self
rancherkey=<<PASTE YOUR RANCHER KEY>>
ranchersecretkey=<<PASTE YOUR RANCHER SECRET KEY>>
rancherserverurl=<<PASTE YOUR RANCHER URL>>>
servicename=$(curl -s $ranchermeta/service/name)
echo $servicename
projectname=$(curl -s $ranchermeta/stack/environment_name)
echo $projectname
urlproject=$(curl -s -u "$rancherkey:$ranchersecretkey" -H 'Accept: application/json' $rancherserverurl/v2-beta/projects?name=$projectname | jq -r '.data[0].links.self')
echo $urlproject
urlservice=$(curl -s -u "$rancherkey:$ranchersecretkey" -H 'Accept: application/json' $urlproject/services/?name=$servicename | jq -r '.data[0].links.self')
if [[ "$urlservice" == 'null' ]]; then
echo "pas de service $servicename dans le projet rancher $projectname"
exit
fi
echo $urlservice
urlremoveservice=$(curl -s -u "$rancherkey:$ranchersecretkey" -H 'Accept: application/json' $urlservice | jq -r '.actions.remove')
echo $urlremoveservice
removedurl=$(curl -s -u "$rancherkey:$ranchersecretkey" -X DELETE -H 'Accept: application/json' $urlremoveservice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment