github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/acceptancetests/repository/charms/simple-resolve/hooks/install (about)

     1  #!/bin/bash
     2  
     3  # Simple install hook that errors the first time it is run, on any subsequent 
     4  # run the hook will succeed (unless the canary file is removed).
     5  
     6  canary_file=/tmp/resolver.canary
     7  success_file=/tmp/resolver.success
     8  
     9  function exit_error() {
    10      status-set blocked "Install hook failed on: $1 attempts." || true
    11      exit 1
    12  }
    13  
    14  if [ ! -e ${canary_file} ]; then
    15      echo "No canary file, exiting error."
    16      echo 1 > ${canary_file}
    17      exit_error 1
    18  fi
    19  
    20  # Need to error for x amount of times before juju stops trying automatically.
    21  run_count=$(cat ${canary_file})
    22  
    23  # For now juju is always re-trying. Need to just exit regardless.
    24  echo $((${run_count}+1)) > ${canary_file}
    25  exit_error ${run_count}
    26  
    27  # This will be useful when install error retries are limited to n-times. For 
    28  # now it retries forever and thus there is no exit condition.
    29  # if [ ${run_count} -le 3 ]; then
    30  #     echo "Incrementing and erroring"
    31  #     echo $((${run_count}+1)) > ${canary_file}
    32  #     exit_error ${run_count}
    33  # else
    34  #     echo "Canary file found, exit success."
    35  #     touch ${success_file}
    36  #     status-set maintenance "Install hook succeeded." || true
    37  #     exit 0
    38  # fi
    39