github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/acceptancetests/repository/charms/chaos-monkey/actions/start (about)

     1  #!/bin/bash -eux
     2  dry_run="$(config-get dry-run)"
     3  chaos_dir="$(config-get chaos-dir)"
     4  exclude_command="$(action-get exclude-command)"
     5  exclude_group="$(action-get exclude-group)"
     6  enablement_timeout="$(action-get enablement-timeout)"
     7  include_command="$(action-get include-command)"
     8  include_group="$(action-get include-group)"
     9  total_timeout="$(action-get total-timeout)"
    10  monkey_id="$(action-get monkey-id)"
    11  mode="$(action-get mode)"
    12  monkey_id=${monkey_id:-${JUJU_ACTION_TAG#action-}}
    13  action-set action-parameters.dry-run="${dry_run}"
    14  action-set action-parameters.chaos-dir="${chaos_dir}"
    15  action-set action-parameters.charm-dir="${CHARM_DIR}"
    16  action-set action-parameters.exclude-command="${exclude_command}"
    17  action-set action-parameters.exclude-group="${exclude_group}"
    18  action-set action-parameters.enablement-timeout="${enablement_timeout}"
    19  action-set action-parameters.include-command="${include_command}"
    20  action-set action-parameters.include-group="${include_group}"
    21  action-set action-parameters.monkey-id=${monkey_id}
    22  action-set action-parameters.total-timeout="${total_timeout}"
    23  action-set action-parameters.mode="${mode}"
    24  
    25  # Create a unique directory to run and log this monkeys actions.
    26  target_dir=${chaos_dir}/chaos_monkey.${monkey_id}
    27  mkdir -p ${target_dir}/log
    28  if [[ -d ${CHARM_DIR}/chaos-monkey ]]; then
    29      cp -a ${CHARM_DIR}/chaos-monkey ${target_dir}
    30  fi
    31  
    32  # Run the Chaos Monkey
    33  cmd="python ${target_dir}/chaos-monkey/runner.py"
    34  cmd+=" ${target_dir}"
    35  if [[ -n ${exclude_command:-} ]]; then
    36      cmd+=" --exclude-command ${exclude_command}"
    37  fi
    38  if [[ -n ${exclude_group:-} ]]; then
    39      cmd+=" --exclude-group ${exclude_group}"
    40  fi
    41  if [[ -n ${include_command:-} ]]; then
    42      cmd+=" --include-command ${include_command}"
    43  fi
    44  if [[ -n ${include_group:-} ]]; then
    45      cmd+=" --include-group ${include_group}"
    46  fi
    47  if [[ -n ${total_timeout:-} ]]; then
    48      cmd+=" --total-timeout ${total_timeout}"
    49  fi
    50  if [[ -n ${enablement_timeout:-} ]]; then
    51      cmd+=" --enablement-timeout ${enablement_timeout}"
    52  fi
    53  if [[ -n ${mode:-} && "single" == "$mode" ]]; then
    54      cmd+=" --run-once"
    55  fi
    56  action-set action-info.runner-cmd="${cmd}"
    57  action-set action-info.runner-log="${target_dir}/log/results.log"
    58  if [[ ${dry_run-} != True ]]; then
    59      # Start the Chaos runner in a subprocess with nohup and in the background.
    60      # In this way it's PPID becomes init and further juju actions are not
    61      # blocked.
    62      (nohup ${cmd} >> ${target_dir}/log/nohup.out 2>&1 &)
    63  fi