check_pid() {
  # check for PID file
  if [ -f $PID ]; then
     # PID file is there, is it readable?
     if [ -r $PID ]; then
        # it's readable, is there a process?
        if [ "$DAEMON $CMDLINE" = "`ps -p\`cat $PID\` -o cmd h`" ]; then
           # looks like it's already running
           echo "$NAME is already running."
           exit 0
        else
           # looks like a stale PID file
           rm -f $PID
        fi
     else
        echo "$PID file already exists, but is not accessible."
        exit 1
     fi
  fi
}
