فهرست منبع

PID wrapper for dmx.py

Zach Isbach 7 سال پیش
والد
کامیت
d5a23bb65a
1فایلهای تغییر یافته به همراه37 افزوده شده و 0 حذف شده
  1. 37 0
      dmx/dmxLauncher.sh

+ 37 - 0
dmx/dmxLauncher.sh

@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# Ensure we have a valid TMP path
+if [ -z "${TMPDIR}" ]; then
+	TMPDIR="/tmp"
+fi
+if [ ! -d "${TMPDIR}" ]; then
+	echo "Invalid TMPDIR: ${TMPDIR}" 1>&2
+	exit 1
+fi
+
+# Grab the existing PID, if any
+PID=0
+PIDFILE="${TMPDIR}/dmx.pid"
+if [ -s "${PIDFILE}" ]; then
+	read p < "${PIDFILE}"
+	if [ -n "${p}" ] && [ $p -gt 1 ]; then
+		PID=$p
+	fi
+fi
+
+# Validate the PID, if it exists
+if [ $PID -gt 1 ]; then
+	if ! ps -o command= -p "${PID}" | \
+		grep -q -E '^\S+/Python.app/Contents/MacOS/Python /Users/tv/bin/video/dmx/dmx.py'; then
+			PID=0
+	fi
+fi
+
+# Exit if we're running
+if [ $PID -gt 1 ]; then
+	exit 0
+fi
+
+# Launch if we are not running
+echo $$ > "${PIDFILE}"
+exec "${HOME}/bin/video/dmx/dmx.py"