prepare script runs as root now
This commit is contained in:
parent
51c3c03c9e
commit
7d65402dfa
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
set -eux -o pipefail
|
set -eux -o pipefail
|
||||||
|
|
||||||
|
readonly USER=ubuntu
|
||||||
readonly APP_DIR="/home/ubuntu/app"
|
readonly APP_DIR="/home/ubuntu/app"
|
||||||
readonly CERTS_DIR="/home/ubuntu/certs"
|
readonly CERTS_DIR="/home/ubuntu/certs"
|
||||||
readonly APP_REPO_DIR="/home/ubuntu/app.git"
|
readonly APP_REPO_DIR="/home/ubuntu/app.git"
|
||||||
@ -15,44 +16,47 @@ readonly SERVER_NAME="<%= serverName %>"
|
|||||||
readonly ENV="<%= env %>"
|
readonly ENV="<%= env %>"
|
||||||
|
|
||||||
swap_file="/swap"
|
swap_file="/swap"
|
||||||
[[ -f "${swap_file}" ]] && sudo swapoff "${swap_file}"
|
[[ -f "${swap_file}" ]] && swapoff "${swap_file}"
|
||||||
if [[ "${ENV}" == "dev" ]]; then
|
if [[ "${ENV}" == "dev" ]]; then
|
||||||
sudo fallocate -l 2048m "${swap_file}" # t1.micro has 1GB RAM
|
fallocate -l 2048m "${swap_file}" # t1.micro has 1GB RAM
|
||||||
elif [[ "${ENV}" == "staging" ]]; then
|
elif [[ "${ENV}" == "staging" ]]; then
|
||||||
sudo fallocate -l 2048m "${swap_file}" # t1.micro has 1GB RAM
|
fallocate -l 2048m "${swap_file}" # t1.micro has 1GB RAM
|
||||||
else
|
else
|
||||||
sudo fallocate -l 2048m "${swap_file}" # t1.micro has 1GB RAM
|
fallocate -l 2048m "${swap_file}" # t1.micro has 1GB RAM
|
||||||
fi
|
fi
|
||||||
sudo chmod 600 "${swap_file}"
|
chmod 600 "${swap_file}"
|
||||||
sudo mkswap "${swap_file}"
|
mkswap "${swap_file}"
|
||||||
sudo swapon "${swap_file}"
|
swapon "${swap_file}"
|
||||||
if ! grep "${swap_file}" /etc/fstab; then
|
if ! grep "${swap_file}" /etc/fstab; then
|
||||||
sudo bash -c "echo '${swap_file} none swap sw 0 0' >> /etc/fstab"
|
bash -c "echo '${swap_file} none swap sw 0 0' >> /etc/fstab"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# install git
|
# install git
|
||||||
sudo apt-get update
|
apt-get update
|
||||||
sudo apt-get install -y git
|
apt-get install -y git
|
||||||
git config --global user.name e2etest
|
sudo -u ubuntu git config --global user.name e2etest
|
||||||
git config --global user.email e2etest@cloudron.io
|
sudo -u ubuntu git config --global user.email e2etest@cloudron.io
|
||||||
|
|
||||||
# install node v4.x LTS https://github.com/nodesource/distributions
|
# install node LTS
|
||||||
sudo apt-get install -y python-software-properties python g++ make
|
apt-get install -y python-software-properties python g++ make
|
||||||
curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -
|
mkdir -p /usr/local/node-4.2.2
|
||||||
sudo apt-get install -y nodejs
|
curl -sL https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz | tar zxvf - --strip-components=1 -C /usr/local/node-4.2.2
|
||||||
|
ln -sf /usr/local/node-4.2.2/bin/node /usr/bin/node
|
||||||
|
ln -sf /usr/local/node-4.2.2/bin/npm /usr/bin/npm
|
||||||
|
npm config set prefix /usr/local
|
||||||
|
|
||||||
# copy over ssh keys
|
# copy over ssh keys
|
||||||
sudo mv "/tmp/id_rsa" "${HOME}/.ssh/id_rsa"
|
mv "/tmp/id_rsa" "${HOME}/.ssh/id_rsa"
|
||||||
sudo mv "/tmp/id_rsa.pub" "${HOME}/.ssh/id_rsa.pub"
|
mv "/tmp/id_rsa.pub" "${HOME}/.ssh/id_rsa.pub"
|
||||||
echo -e "Host *.cloudron.me\n StrictHostKeyChecking no" > ${HOME}/.ssh/config
|
echo -e "Host *.cloudron.me\n StrictHostKeyChecking no" > ${HOME}/.ssh/config
|
||||||
|
|
||||||
# install tmpreaper (runs everyday and clean tmp)
|
# install tmpreaper (runs everyday and clean tmp)
|
||||||
sudo apt-get install -y tmpreaper
|
apt-get install -y tmpreaper
|
||||||
sudo sed -e 's/SHOWWARNING=true/# SHOWWARNING=true/' -i /etc/tmpreaper.conf
|
sed -e 's/SHOWWARNING=true/# SHOWWARNING=true/' -i /etc/tmpreaper.conf
|
||||||
|
|
||||||
# install pm2
|
# install pm2
|
||||||
sudo npm install -g pm2 pm2-run forever
|
npm install -g pm2 pm2-run forever
|
||||||
sudo rm -rf ~/.npm # .npm will get owned by root after "sudo npm install -g"
|
rm -rf ~/.npm # .npm will get owned by root after "npm install -g"
|
||||||
|
|
||||||
# installer
|
# installer
|
||||||
rm -rf "${HOME}/release" && mv /tmp/release "${HOME}"
|
rm -rf "${HOME}/release" && mv /tmp/release "${HOME}"
|
||||||
@ -94,10 +98,12 @@ pm2 save
|
|||||||
EOF
|
EOF
|
||||||
chmod +x "${APP_REPO_DIR}/hooks/post-receive"
|
chmod +x "${APP_REPO_DIR}/hooks/post-receive"
|
||||||
|
|
||||||
|
|
||||||
# create empty ecosystem.json
|
# create empty ecosystem.json
|
||||||
touch "${ECOSYSTEM}"
|
touch "${ECOSYSTEM}"
|
||||||
|
|
||||||
|
# fix ownership
|
||||||
|
chown -R $USER:$USER /home/$USER
|
||||||
|
|
||||||
# run pm2 as current user ubuntu to avoid pm2 running as root below
|
# run pm2 as current user ubuntu to avoid pm2 running as root below
|
||||||
pm2 status
|
pm2 status
|
||||||
|
|
||||||
@ -105,5 +111,5 @@ pm2 status
|
|||||||
pm2 updatePM2
|
pm2 updatePM2
|
||||||
|
|
||||||
# setup the init scripts
|
# setup the init scripts
|
||||||
sudo pm2 startup -u ubuntu
|
pm2 startup -u $USER
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user