job_start.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # vim: filetype=sh ts=4 sw=4 sts=4 et:
  3. #
  4. # Wait until file exists, then spawn.
  5. # This is not Python because the start_tmpl from pbsmrtpipe always runs bash.
  6. # But we use the .py extension because we want this installed with our Python
  7. # code, so we do not need to deal with mobs for installation. (But we might
  8. # need to chmod +x.)
  9. #
  10. # This can be run via
  11. #
  12. # bash -c pwatcher/mains.job_start.py myprog 60
  13. #
  14. # Note: If anyone replaces this, you must ensure that running this is exactly equivalent
  15. # to running the "executable". In other words, no 'mkdir', no 'cd', etc. That will help
  16. # with debugging.
  17. set -vex
  18. executable=${PYPEFLOW_JOB_START_SCRIPT}
  19. timeout=${PYPEFLOW_JOB_START_TIMEOUT:-60} # wait 60s by default
  20. # Wait up to timeout seconds for the executable to become "executable",
  21. # then exec.
  22. #timeleft = int(timeout)
  23. while [[ ! -x "${executable}" ]]; do
  24. if [[ "${timeout}" == "0" ]]; then
  25. echo "timed out waiting for (${executable})"
  26. exit 77
  27. fi
  28. echo "not executable: '${executable}', waiting ${timeout}s"
  29. sleep 1
  30. timeout=$((timeout-1))
  31. done
  32. /bin/bash ${executable}