2017-10-23 2 views
0

Ich habe ein Tutorial über die Verbindung eines Himbeer-Pi mit dem AWS-Greengrass verfolgt und erhalte immer einen Segmentierungsfehler im letzten Schritt. AWS hat mir dieses greengrassd Shell-Skript zur Verfügung gestellt, aber wenn ich es ausführe, bekomme ich einen Segmentierungsfehler. Ich habe keine Ahnung, warum es diesen Fehler wirft, damit jede Hilfe geschätzt wird.Shell-Skript-Segmentierungsfehler - AWS

AWS Greengrass Tutorial/RaspberryPi

Fehler

[email protected]:/greengrass/ggc/packages/1.1.0 $ sudo ./greengrassd start 
Setting up greengrass daemon 
Validating execution environment 
Found cgroup subsystem: cpu 
Found cgroup subsystem: cpuacct 
Found cgroup subsystem: blkio 
Found cgroup subsystem: memory 
Found cgroup subsystem: devices 
Found cgroup subsystem: freezer 
Found cgroup subsystem: net_cls 

Starting greengrass daemon./greengrassd: line 158: 2254 Segmentation fault  nohup $COMMAND > /dev/null 2> $CRASH_LOG < /dev/null 

Greengrass daemon 2254 failed to start 

greengrassd Skript

#!/usr/bin/env bash 
##########Environment Requirement for Greengrass Daemon########## 
# by default, the daemon assumes it's going to be launched from a directory 
# that has the following structure: 
# GREENGRASS_ROOT/ 
#     greengrassd 
#     bin/daemon 
#     configuration/ 
#        group/group.json 
#        certs/server.crt 
#     lambda/ 
#      system_lambda1/... 
#      system_lambda2/... 
# root cgroup has to be mounted separately, this script doesn't do that for you. 
################################################################# 

set -e 

PWD=$(cd $(dirname "$0"); pwd) 
GGC_PKG_HOME=$(readlink -f $PWD) 

GG_HOME=$(cd $GGC_PKG_HOME/../../; pwd) 
CRASH_LOG=$GG_HOME/var/log/crash.log 

GGC_ROOT_FS=$GGC_PKG_HOME/ggc_root 
PID_FILE=/var/run/greengrassd.pid 
FS_SETTINGS=/proc/sys/fs 
GGC_GROUP=ggc_group 
GGC_USER=ggc_user 

MAX_DAEMON_KILL_WAIT_SECONDS=60 
RETRY_SIGTERM_INTERVAL_SECONDS=20 

if [ -z "$COMMAND" ]; then 
    COMMAND="$GGC_PKG_HOME/bin/daemon -core-dir=$GGC_PKG_HOME -greengrassdPid=$$" 
fi 

# Function ran as part of initial setup 
setup() { 
    echo "Setting up greengrass daemon" 
    mkdir -p $GGC_ROOT_FS 

    # Mask greengrass directory for containers 
    mknod $GGC_ROOT_FS/greengrass c 1 3 &>/dev/null || true 

    mkdir -p $(dirname "$CRASH_LOG") 
} 

validatePlatformSecurity() { 

    if [[ -f $FS_SETTINGS/protected_hardlinks && 
      -f $FS_SETTINGS/protected_symlinks ]]; then 

    PROT_HARDLINK_VAL=$(cat $FS_SETTINGS/protected_hardlinks) 
    PROT_SOFTLINK_VAL=$(cat $FS_SETTINGS/protected_symlinks) 

    if [[ "$PROT_HARDLINK_VAL" -ne 1 || "$PROT_SOFTLINK_VAL" -ne 1 ]]; then 
     echo "AWS Greengrass detected insecure OS configuration: No hardlink/softlink protection enabled." | tee -a $CRASH_LOG 
     exit 1 
    fi 
fi 
} 

validateEnvironment() { 
    echo "Validating execution environment" 
    # ensure all commands that the installation script is going to use are available 
    if ! type grep >/dev/null ; then 
     echo "grep command is NOT on the path or is NOT installed on the system" 
     exit 1 
    fi 

    if ! type cat >/dev/null ; then 
     echo "cat command is NOT on the path or is NOT installed on the system" 
     exit 1 
    fi 

    if ! type awk >/dev/null ; then 
     echo "awk command is NOT on the path or is NOT installed on the system" 
     exit 1 
    fi 

    if ! type id >/dev/null ; then 
     echo "id command is NOT on the path or is NOT installed on the system" 
     exit 1 
    fi 

    if ! type ps >/dev/null ; then 
     echo "ps command is NOT on the path or is NOT installed on the system" 
     exit 1 
    fi 

    if ! type sqlite3 >/dev/null ; then 
     echo "sqlite3 command is NOT on the path or is NOT installed on the system" 
     exit 1 
    fi 

    # the script needs to be run as root 
    if [ ! $(id -u) = 0 ]; then 
     echo "The script needs to be run using sudo" 
     exit 1 
    fi 

    if ! id $GGC_USER >/dev/null ; then 
     echo "${GGC_USER} doesn't exist. Please add a user ${GGC_USER} on the system" 
     exit 1 
    fi 

    if ! grep -q $GGC_GROUP /etc/group ; then 
     echo "${GGC_GROUP} doesn't exist. Please add a group ${GGC_GROUP} on the system" 
     exit 1 
    fi 

    # ensure that kernel supports cgroup 
    if [ ! -e /proc/cgroups ]; then 
     echo "The kernel in use does NOT support cgroup." 
     exit 1 
    fi 

    # assume that all kernel supported subsystems, which are listed in /proc/cgroups, are going to be used 
    # so check whether all of them are mounted. 
    for d in `awk '$4 == 1 {print $1}' /proc/cgroups`; do 
     if cat /proc/self/cgroup | grep -q $d; then 
      echo "Found cgroup subsystem: $d" 
     else 
      # exit with error if can't find cgroup 
      echo "The cgroup subsystem is not mounted: $d" 
      exit 1 
     fi 
    done 
} 

finish() { 
    pid=$1 
    echo "$pid" > $PID_FILE 
    echo "" 
    echo -e "\e[0;32mGreengrass successfully started with PID: $pid\e[0m" 
    exit 0 
} 

start() { 
    setup 
    if [[ $INSECURE -ne 1 ]]; then 
     validatePlatformSecurity 
    fi 

    validateEnvironment 

    trap 'finish $pid' SIGUSR1 

    echo "" 
    echo -n "Starting greengrass daemon" 
    if nohup $COMMAND >/dev/null 2>$CRASH_LOG < /dev/null & 
    then 
     pid=$! 
     # sleep 10 seconds to wait for daemon to start or exit 
     sleep 10 & 
     wait $! 

     echo "" 
     echo "Greengrass daemon $pid failed to start" 
     echo -e "\e[0;31m$(cat $CRASH_LOG)\e[0m" 
     exit 1 
    else 
     echo "Failed to start Greengrass daemon" 
     exit 1 
    fi 
} 

version() { 
    $GGC_PKG_HOME/bin/daemon --version 
} 

stop() { 
    if [ -f $PID_FILE ]; then 
     PID=$(cat $PID_FILE) 
     echo "Stopping greengrass daemon of PID: $PID" 

     if [ ! -e "/proc/$PID" ]; then 
      rm $PID_FILE 
      echo "Process with pid $PID does not exist already" 
      return 0 
     fi 

     echo -n "Waiting" 
     kill "$PID" > /dev/null 2>&1 
     total_sleep_seconds=0 
     until [ "$total_sleep_seconds" -ge "$MAX_DAEMON_KILL_WAIT_SECONDS" ]; do 
      sleep 1 

      # If the pid no longer exists, we're done, remove the pid file and exit. Otherwise, just increment the loop counter 
      if [ ! -e "/proc/$PID" ]; then 
       rm $PID_FILE 
       echo -e "\nStopped greengrass daemon, exiting with success" 
       break 
      else 
       total_sleep_seconds=$(($total_sleep_seconds+1)) 
       echo -n "." 
      fi 

      # If it has been $RETRY_SIGTERM_INTERVAL_SECONDS since the last SIGTERM, send SIGTERM 
      if [ $(($total_sleep_seconds % $RETRY_SIGTERM_INTERVAL_SECONDS)) -eq "0" ]; then 
       kill "$PID" > /dev/null 2>&1 
      fi 
     done 

     if [ $total_sleep_seconds -ge $MAX_DAEMON_KILL_WAIT_SECONDS ] && [ -e "/proc/$PID" ]; then 
      # If we are here, we never exited in the previous loop and the pid still exists. Exit with failure. 
      kill -9 "$PID" > /dev/null 2>&1 
      echo -e "\nProcess with pid $PID still alive after timeout of $MAX_DAEMON_KILL_WAIT_SECONDS seconds. Forced kill process, exiting with failure." 
      exit 1 
     fi 
    fi 
} 

usage() { 
    echo "" 
    echo "Usage: $0 [FLAGS] {start|stop|restart}" 
    echo "" 
    echo -e "[FLAGS]: \n -i, --insecure \t Run GGC in insecure mode without hardlink/softlink protection, (highly discouraged for production use) \n -v, --version \t\t Outputs the version of GGC." 
    echo "" 
    exit 1 
} 

if [[ $# -eq 0 ]]; then 
    usage 
fi 

for var in "[email protected]" 
do 
    case "$var" in 
    -v|--version) 
     version 
     exit 0 
     ;; 
    esac 
done 

while [[ $# -gt 0 ]] 
do 
    key="$1" 
    case $key in 
     -i|--insecure) 
      mkdir -p $(dirname "$CRASH_LOG") 
      echo "Warning! You are running in insecure mode, this is highly discouraged!" | tee -a $CRASH_LOG 
      INSECURE=1 
      ;; 
     -h|--help) 
      usage 
      ;; 
     start) 
      stop 
      start 
      ;; 
     stop) 
      stop 
      ;; 
     restart) 
      stop 
      start 
      ;; 
     *) 
      usage 
    esac 
    shift 
done 
+0

Wenn bash bei der Verarbeitung einer leeren Zeile (158 im Skript, das Sie eingefügt haben, leer ist) wirklich defaults ist, riskiere ich die Vermutung, dass der Speicher Ihres pi fehlerhaft ist. – tink

Antwort

0

@ Jim Vielleicht das Modell Pi überprüfen Sie verwenden?

Es scheint, dass die Pi-Version von Greengrass für ARMv7-A ist. Ich habe dieses Problem auch und ich benutze ein älteres Modell 1 B +, das ist ARMv6Z (https://en.wikipedia.org/wiki/Raspberry_Pi#Specifications).

Der Fehler, den wir gesucht haben, um die Leitung 158 zu sehen, ist das ./greengrassd Skript für den eigentlichen Prozess warten zu laufen:

sudo /greengrass/ggc/packages/1.1.0/bin/daemon -core-dir=/greengrass/ggc/packages/1.1.0 -greengrassdPid=641

/greengrass/ggc/packages/1.1.0/bin/daemon ist die Binärdatei. Wenn Sie den obigen Befehl direkt in der Konsole ausführen, wird er mit demselben Segmentierungsfehlerfehler beendet.

AWS empfiehlt die Verwendung des Pi 3, also denke ich, dass es daran arbeiten wird.