我正在创建一个自定义AMI
,其中具有以下代码来安装nodejs
和pm2
来托管我的有角度的通用项目。
代码库取自AWS GitHub repo,我只是更改了节点版本。
#!/bin/bash -xe
# Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
. $BUILDER_DIR/CONFIG
### INSTALL AND VALIDATE NODE ####
echo "SETTING UP NODE ON THE INSTANCE"
yum install -y wget tree
mkdir -p $NODE_DIR
echo "Downloading node from nodejs.org...."
wget https://nodejs.org/dist/latest/node-v11.12.0-linux-arm64.tar.gz -O $BUILDER_DIR/node-v11.12.0-linux-arm64.tar.gz
tar -zxf $BUILDER_DIR/node-v11.12.0-linux-arm64.tar.gz -C $NODE_DIR
echo "Validate Node.js got installed."
if [ -a $NODE_DIR/node-v11.12.0-linux-arm64/bin/node ]; then
NODE_VER=`$NODE_DIR/node-v11.12.0-linux-arm64/bin/node --version`
if [ -z "$NODE_VER" ]; then
echo "Node could not be installed. "
else
echo "Node successfully installed.."
fi
fi
echo "Creating base directories for platform."
mkdir -p $BEANSTALK_DIR/deploy/appsource/
mkdir -p /var/app/staging
mkdir -p /var/app/current
mkdir -p /var/log/nginx/healthd/
chown nginx.nginx /var/log/nginx/healthd/
yum install -y git jq
## WRITE NODE_DIR TO CONFIG ON INSTANCE TO BE AVAILABLE FOR HOOKS
mkdir -p $CONTAINER_CONFIG_FILE_DIR
echo "NODE_DIR=$NODE_DIR/node-v11.12.0-linux-arm64" >> $CONTAINER_CONFIG
echo "CONTAINER_SCRIPTS_DIR=$CONTAINER_SCRIPTS_DIR" >> $CONTAINER_CONFIG
##### INSTALL PM2 ######
echo "install pm2 globally"
$NODE_DIR/node-v11.12.0-linux-arm64/bin/npm install -g minimatch@3.0.4
$NODE_DIR/node-v11.12.0-linux-arm64/bin/npm install -g pm2@2.10.4
ls -l $NODE_DIR/node-v11.12.0-linux-arm64/bin
echo "PATH=$PATH:$NODE_DIR/node-v11.12.0-linux-arm64/bin" >> ~/.bashrc
PATH=$PATH:$NODE_DIR/node-v11.12.0-linux-arm64/bin
echo `which pm2`
echo "Setting up PM2 log-rotate"
$NODE_DIR/node-v11.12.0-linux-arm64/bin/pm2 install pm2-logrotate
## Add node path to Beanstalk profile
echo "export PATH=$NODE_DIR/node-v11.12.0-linux-arm64/bin:\$PATH:/usr/local/bin" >> /opt/elasticbeanstalk/lib/ruby/profile.sh
echo "export PM2_HOME=/etc/pm2" >> /opt/elasticbeanstalk/lib/ruby/profile.sh
mkdir -p /etc/pm2/
chmod -R 755 /etc/pm2
我收到以下错误
/tmp/builder//setup-scripts/05-install-nodejs.sh: line 25: /var/nodejs/node-v11.12.0-linux-arm64/bin/node: cannot execute binary file
即
NODE_VER =
$NODE_DIR/node-v11.12.0-linux-arm64/bin/node --version