OSDN Git Service

adds the `fly_prune_workers_main` script.
[metasearch/grid-chef-repo.git] / cookbooks / concourse-ci / templates / default / usr / local / bin / fly_prune_workers
1 #!/usr/bin/env bash
2
3 PATH=.:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:`dirname $0`
4
5 target=''
6
7 usage() {
8   echo 'Usage: prune_workers -t $CC_TARGET'
9   echo
10   echo "Options:"
11   echo "  -h: this help."
12   echo "  -t: target name."
13   echo
14 }
15
16 ARGS="$@"
17 # Validation
18 while getopts 't:h' OPT; do
19   case $OPT in
20     't' )
21       target=$OPTARG
22       ;;
23     'h' )
24       usage
25       exit 0
26       ;;
27     '?' )
28       usage
29       exit 1
30       ;;
31   esac
32 done
33
34 shift $((OPTIND - 1))
35
36 if [ $# != 0 ]; then
37   usage
38   exit 1
39 fi
40
41 if [ -z $target ]; then
42   usage
43   exit 1
44 fi
45
46 fly -t $target ws | awk '$6=="stalled" {print $1}' | xargs -t -n 1 --no-run-if-empty fly -t $target prune-worker -w