diff --git a/sbin/CheckPid b/sbin/CheckPid new file mode 100755 index 0000000..cbe17cf --- /dev/null +++ b/sbin/CheckPid @@ -0,0 +1,28 @@ +#!/bin/bash + +PIDFILE=$1 + +if [ ! ${PIDFILE} ]; then + echo "Usage: $0 " + exit 10 +fi + +PID=$(cat ${PIDFILE}) +PSNAME=$(ps -ef|awk '{ if ( $2 == "'${PID}'" ) print $8 }'|cut -d "." -f1) +SEEKNAME=$(basename ${PIDFILE}|cut -d"." -f1) +if [ "${PSNAME}" ]; then + if echo ${SEEKNAME}|grep -q $(basename ${PSNAME}); then + logger -p info -t upstart "Found running Prozess ${PSNAME} for ${PIDFILE}; aborting startup" + exit 2 + else + logger -p info -t upstart "PIDFILE ${PIDFILE} does not point to the correct running prozess" + logger -p info -t upstart "cleanup ${PIDFILE} and start the prozess" + rm ${PIDFILE} + exit 0 + fi +else + logger -p info -t upstart "PIDFILE ${PIDFILE} does not point to any prozess" + logger -p info -t upstart "Cleanup ${PIDFILE} and start the prozess" + rm ${PIDFILE} + exit 0 +fi