sh ubuntu linux上的puppeteer ami(xvfb setup)+用于自动缩放的cloudwatch指标

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh ubuntu linux上的puppeteer ami(xvfb setup)+用于自动缩放的cloudwatch指标相关的知识,希望对你有一定的参考价值。

#!/bin/bash

export HOME=/home/ubuntu
export PM2_HOME=$HOME/.pm2
export NODE_ENV=production
export NPM_TOKEN="TOKEN"
export LOCAL_HOSTNAME=$(curl http://169.254.169.254/latest/meta-data/local-hostname)
export PUBLIC_HOSTNAME=$(curl http://169.254.169.254/latest/meta-data/public-hostname)

TIMEZONE=$(echo "America/Chicago
America/New_York
America/Los_Angeles" | shuf -n 1)
echo "Setting timezone $TIMEZONE"
timedatectl set-timezone $TIMEZONE

sleep 5

cat <<EOF > ~/.npmrc
//registry.npmjs.org/:_authToken=\${NPM_TOKEN}
EOF

curl -sL https://deb.nodesource.com/setup_9.x | bash -

apt-get update
apt-get install -y libopencv-dev libpoppler-qt5-dev libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev build-essential g++ tesseract-ocr nodejs \
  gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
  libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
  libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
  libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
  ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libnss3-tools \
  libdatetime-perl redis-server htop jq xvfb

# setup xvfb init.d service
cat <<EOF > /etc/systemd/system/xvfb.service
[Unit]
Description=Virtual Frame Buffer X Server
After=network.target

[Service]
ExecStart=/usr/bin/Xvfb :99 -screen 0 1x1x24 -ac +extension GLX +render -noreset

[Install]
WantedBy=multi-user.target
EOF
systemctl enable xvfb.service
systemctl start xvfb.service
export XVFB_DISPLAY=:99

cd $HOME
cat <<EOF > check-version-update.sh
#!/bin/sh

LOCKFILE=/tmp/check-version-update.lock
if [ -e \${LOCKFILE} ] && kill -0 \`cat \${LOCKFILE}\`; then
  echo "already running"
  exit
fi

# make sure the lockfile is removed when we exit and then claim it
trap "rm -f \${LOCKFILE}; exit" INT TERM EXIT
echo \$\$ > \${LOCKFILE}

export HOME=$HOME
export PM2_HOME=$PM2_HOME
export NPM_TOKEN=$NPM_TOKEN

LATEST_VERSION=\$(npm view @username/yourpackage dist-tags.latest 2>/dev/null)
CURRENT_VERSION=\$(npm ls @username/yourpackage --global --json --depth=0 | jq '.dependencies."@username/yourpackage".version' --raw-output 2>/dev/null)

echo "Current: \$CURRENT_VERSION"
echo "Latest: \$LATEST_VERSION"

if [ \$CURRENT_VERSION = \$LATEST_VERSION ]; then
  echo "current version is latest. skipping update sequence"
  exit 0
fi

npmInstallLatestVersion() {
  echo 'npm install'
  sudo -E npm i --unsafe-perm -g @username/yourpackage@\$LATEST_VERSION || { echo 'failed npm install'; return 1; }
}

npmCacheClean() {
  echo 'npm cache clean'
  sudo -E npm cache clean --force || { echo 'failed npm cache clean'; return 1; }
}

rmRfyourpackage() {
  echo 'rm -rf yourpackage'
  sudo rm -rf /usr/lib/node_modules/@username/yourpackage || { echo 'failed rm -rf yourpackage'; return 1; }
}

npmInstallLatestVersion || (npmCacheClean && rmRfyourpackage && npmInstallLatestVersion)

echo "Reloading PM2"
sudo -E pm2 reload all

rm -f \${LOCKFILE}
EOF
chmod +x check-version-update.sh

npm i --silent --unsafe-perm -g @username/yourpackage@latest pm2@latest

pm2 install pm2-logrotate
pm2 set pm2-logrotate:retain 1
pm2 start -i 12 --node-args="--harmony" bots

cd $HOME
git clone -q https://github.com/nicoandmee/aws-scripts-mon
echo "* * * * * ubuntu cd $HOME/aws-scripts-mon && ./mon-put-instance-data.pl --count-process --from-cron --aggregated=only --auto-scaling=only" >> /etc/crontab
echo "* * * * * root cd $HOME && ./check-version-update.sh" >> /etc/crontab
echo "* * * * * root killall --older-than 60m chrome" >> /etc/crontab


echo "* * * * * root cd $HOME && ./start.sh" >> /etc/crontab

以上是关于sh ubuntu linux上的puppeteer ami(xvfb setup)+用于自动缩放的cloudwatch指标的主要内容,如果未能解决你的问题,请参考以下文章

sh bash文件将dvd或cd光盘刻录到硬盘驱动器磁盘上作为linux / Ubuntu上的iso文件

ubuntu中/bin/bash与/bin/sh,区别较大吗

在ubuntu Linux中使用命令sh updateip.sh命令出现unable to resolve host

ubuntu下怎么打开vivado

sh Ubuntu:清理Ubuntu上的启动分区

sh [ConoHa上的Ubuntu上的Docker] aa