Linux Shell脚本分段错误-AWS
我一直在遵循一个关于将树莓pi连接到AWS greengrass的教程,在最后一步中,我不断遇到分割错误。AWS为我提供了这个Greengrasd shell脚本,但是当我运行它时,我遇到了一个分段错误。我不知道为什么它会抛出这个错误,所以任何帮助都会被感激 错误Linux Shell脚本分段错误-AWS,linux,shell,amazon-web-services,raspberry-pi,Linux,Shell,Amazon Web Services,Raspberry Pi,我一直在遵循一个关于将树莓pi连接到AWS greengrass的教程,在最后一步中,我不断遇到分割错误。AWS为我提供了这个Greengrasd shell脚本,但是当我运行它时,我遇到了一个分段错误。我不知道为什么它会抛出这个错误,所以任何帮助都会被感激 错误 pi@raspberrypi:/greengrass/ggc/packages/1.1.0 $ sudo ./greengrassd start Setting up greengrass daemon Validating exe
pi@raspberrypi:/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
pi@raspberrypi:/greengrass/ggc/packages/1.1.0$sudo./greengrassd start
设置greengrass守护进程
验证执行环境
找到cgroup子系统:cpu
已找到cgroup子系统:cpuacct
找到cgroup子系统:blkio
找到cgroup子系统:内存
找到cgroup子系统:设备
找到cgroup子系统:冷冻柜
找到cgroup子系统:net\u cls
正在启动greengrass守护进程。/greengrassd:line 158:2254分段错误nohup$命令>/dev/null 2>$CRASH\u LOG
绿草脚本
#!/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 "$@"
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
#/usr/bin/env bash
##########绿草的环境要求##########
#默认情况下,守护进程假定它将从一个目录启动
#其结构如下:
#青草/
#绿草
#bin/守护进程
#配置/
#group/group.json
#certs/server.crt
#兰姆达/
#系统λ1/。。。
#系统λ2/。。。
#根cgroup必须单独装入,此脚本不能为您这样做。
#################################################################
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_文件=/var/run/greengrassd.PID
FS_设置=/proc/sys/FS
GGC_组=GGC_组
GGC_用户=GGC_用户
最大\u守护程序\u杀死\u等待\u秒=60
重试\u SIGTERM\u间隔\u秒=20
如果[-z“$COMMAND”];然后
COMMAND=“$GGC_PKG_HOME/bin/daemon-core dir=$GGC_PKG_HOME-greengrassdPid=$$”
fi
#函数作为初始设置的一部分运行
设置(){
echo“设置绿草守护程序”
mkdir-p$GGC\u ROOT\u FS
#容器的屏蔽绿草目录
mknod$GGC_ROOT_FS/greengrass c1 3&>/dev/null | true
mkdir-p$(dirname“$CRASH_LOG”)
}
validatePlatformSecurity(){
如果[[-f$FS\u设置/受保护\u硬链接&&
-f$FS_设置/受保护的_符号链接]];然后
PROT_HARDLINK_VAL=$(类别$FS_设置/受保护_hardlinks)
PROT_SOFTLINK_VAL=$(类别$FS_设置/受保护的_符号链接)
如果[“$PROT_HARDLINK_VAL”-ne 1 | |“$PROT_SOFTLINK_VAL”-ne 1];则
echo“AWS Greengrass检测到操作系统配置不安全:未启用硬链路/软链路保护。”| tee-一个$CRASH_日志
出口1
fi
fi
}
validateEnvironment(){
echo“验证执行环境”
#确保安装脚本将要使用的所有命令都可用
如果!键入grep>/dev/null;则
echo“grep命令不在路径上或未安装在系统上”
出口1
fi
如果!键入cat>/dev/null;则
echo“cat命令不在路径上或未安装在系统上”
出口1
fi
如果!键入awk>/dev/null;则
echo“awk命令不在路径上或未安装在系统上”
出口1
fi
如果!type id>/dev/null;则
echo“id命令不在路径上或未安装在系统上”
出口1
fi
如果!键入ps>/dev/null;则
echo“ps命令不在路径上或未安装在系统上”
出口1
fi
如果!键入sqlite3>/dev/null;则
echo“sqlite3命令不在路径上或未安装在系统上”
出口1
fi
#脚本需要以root用户身份运行
如果[!$(id-u)=0];则
echo“脚本需要使用sudo运行”
出口1
fi
如果!id$GGC_USER>/dev/null;那么
echo“${GGC\U USER}不存在。请在系统上添加用户${GGC\U USER}”
出口1
fi
如果!grep-q$GGC_GROUP/etc/GROUP;那么
echo“${GGC\U GROUP}不存在。请在系统上添加组${GGC\U GROUP}”
出口1
fi
#确保内核支持cgroup
如果[!-e/proc/cgroups];则
echo“正在使用的内核不支持cgroup。”
出口1
fi
#假设将使用/proc/cgroups中列出的所有内核支持的子系统
#因此,请检查它们是否都已安装。
对于'awk'$4==1{print$1}'/proc/cgroups`中的d;do
如果cat/proc/self/cgroup | grep-q$d;那么
echo“找到cgroup子系统:$d”
其他的
#如果找不到cgroup,则退出并出错
echo“未安装cgroup子系统:$d”
出口1
fi
完成
}
完成(){
pid=$1
回显“$pid”>$pid\U文件
回声“”
echo-e“\e[0;32mGreengrass已成功启动PID:$PID\e[0m”
出口0
}
开始(){
设置
如果[[$unsecure-ne 1]];则
validatePlatformSecurity
fi
验证环境
陷阱“完成$pid”信号1
回声“”
echo-n“正在启动greengrass守护程序”
如果nohup$COMMAND>/dev/null 2>$CRASH\u LOG