dmxLauncher.sh 698 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. # Ensure we have a valid TMP path
  3. if [ -z "${TMPDIR}" ]; then
  4. TMPDIR="/tmp"
  5. fi
  6. if [ ! -d "${TMPDIR}" ]; then
  7. echo "Invalid TMPDIR: ${TMPDIR}" 1>&2
  8. exit 1
  9. fi
  10. # Grab the existing PID, if any
  11. PID=0
  12. PIDFILE="${TMPDIR}/dmx.pid"
  13. if [ -s "${PIDFILE}" ]; then
  14. read p < "${PIDFILE}"
  15. if [ -n "${p}" ] && [ $p -gt 1 ]; then
  16. PID=$p
  17. fi
  18. fi
  19. # Validate the PID, if it exists
  20. if [ $PID -gt 1 ]; then
  21. if ! ps -o command= -p "${PID}" | \
  22. grep -q -E '^\S+/Python.app/Contents/MacOS/Python /Users/tv/bin/video/dmx/dmx.py'; then
  23. PID=0
  24. fi
  25. fi
  26. # Exit if we're running
  27. if [ $PID -gt 1 ]; then
  28. exit 0
  29. fi
  30. # Launch if we are not running
  31. echo $$ > "${PIDFILE}"
  32. exec "${HOME}/bin/video/dmx/dmx.py"