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