-
Notifications
You must be signed in to change notification settings - Fork 2
/
nvm-pm2.sh
executable file
·62 lines (47 loc) · 1.93 KB
/
nvm-pm2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
DEFAULT_NVM_VERSION=16.14.2
NVM_VERSION=$DEFAULT_NVM_VERSION;
# Check if file exists /var/www/site/DockerLocal/versions/nvm-version
if [ -f "/var/www/site/DockerLocal/versions/nvm-version" ]; then
NVM_VERSION=$(</var/www/site/DockerLocal/versions/nvm-version)
fi
# Check if override file exists /var/www/site/DockerLocal/versions/override-nvm-version
if [ -f "/var/www/site/DockerLocal/versions/override-nvm-version" ]; then
NVM_VERSION=$(</var/www/site/DockerLocal/versions/override-nvm-version)
fi
## See if nvm command exists
## If not, install it
source /var/www/.bashrc
if [ ! -d "/var/www/.nvm" ]; then
echo "ℹ️ nvm could not be found"
echo "ℹ️ nvm version $NVM_VERSION will be installed. Override in DockerLocal/versions/override-nvm-version."
echo "⏳ Installing nvm"
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
. /var/www/.nvm/nvm.sh
. /var/www/.bashrc
command -v nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install $NVM_VERSION
# Install pm2
echo "⏳ Installing pm2"
npm install -g pm2
# Source profile
echo "⏳ Sourcing profile: /var/www/.bashrc"
source /var/www/.bashrc
else
echo "✅ nvm already installed"
fi
# Check if ecosystem.config.js has been setup / needs to be setup
if [ ! -f "/var/www/ecosystem.config.js" ] && [ -f "/var/www/site/DockerLocal/ecosystem.config.js" ]; then
echo "ecosystem.config.js exists - going to copy it and start pm2"
# copy ecosystem.config.js
ln -s /var/www/site/DockerLocal/ecosystem.config.js /var/www/
# start pm2
pm2 start
elif [ -f "/var/www/ecosystem.config.js" ]; then
echo "🔄 ecosystem.config.js exists - going to restart pm2"
# restart pm2
pm2 restart all
fi