Last active
May 10, 2023 17:22
-
-
Save diegofcornejo/c687231535b0c5154ebe2d7a732285ce to your computer and use it in GitHub Desktop.
AWS EC2 User data (init script) for Linux AMI 2 ARM A1 or T4G instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REPO="your-repo" | |
OWNER="diegofcornejo" | |
TOKEN="github_developer_token" | |
APPDIR="/home/ec2-user" | |
NODE_VERSION="12.16.3" | |
cd $APPDIR | |
touch init.log | |
echo 'Updating OS' >> init.log | |
yum update -y | |
echo 'Install git' >> init.log | |
yum install -y git | |
echo 'Install node' >> init.log | |
curl -O https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-arm64.tar.xz | |
tar -xvf node-v$NODE_VERSION-linux-arm64.tar.xz | |
cd node-v$NODE_VERSION-linux-arm64 | |
sudo cp -R * /usr/local/ | |
sudo ln -s /usr/local/bin/node /usr/bin/node | |
sudo ln -s /usr/local/lib/node /usr/lib/node | |
sudo ln -s /usr/local/bin/npm /usr/bin/npm | |
cd .. | |
echo 'Install forever' >> init.log | |
npm install -g forever | |
sudo ln -s /usr/local/bin/forever /usr/bin/forever | |
echo 'Clone repo' >> init.log | |
git clone https://[email protected]/$OWNER/$REPO.git | |
echo 'Enter to repo' >> init.log | |
cd $REPO | |
echo 'Install npm packages' >> init.log | |
npm ci | |
echo 'Start server' >> init.log | |
forever start -l $APPDIR/$REPO/server.log server.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment