Created
September 15, 2019 11:37
-
-
Save botic/6362f475801e7faded6a4f72fccbc65a to your computer and use it in GitHub Desktop.
SharedMobility.ai Web API Installation Guide
This file contains 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
{ | |
"apps": [ | |
{ | |
"name": "sharedmobility-web-api", | |
"cwd": "/usr/local/node-apps/sharedmobility-ai/web-api/", | |
"script": "./bin/www", | |
"error_file": "/var/log/node/error.log", | |
"out_file": "/var/log/node/out.log", | |
"max_restarts": 30, | |
"restart_delay": 2000, | |
"instances": 1, | |
"env": { | |
"NODE_ENV": "production", | |
"PORT": "54321" | |
} | |
} | |
] | |
} |
This file contains 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 | |
# First update all packages | |
sudo apt-get update | |
sudo apt-get upgrade | |
# Install Apache Webserver (reverse proxy for node) and enable HTTP2 | |
sudo apt-get install apache2 | |
sudo a2enmod http2 | |
sudo a2enmod proxy | |
sudo a2enmod proxy_http | |
# Create the vhost | |
sudo pico /etc/apache2/sites-available/100-api.sharedmobility.ai.conf | |
sudo mkdir /var/www/api.sharedmobility.ai | |
# Add the following two lines to the Apache config with: | |
# | |
# ServerSignature Off | |
# ServerTokens Prod | |
sudo pico -w /etc/apache2/apache2.conf | |
# use the config files provided in this gist and update both vhost configs: | |
sudo pico -w /etc/apache2/sites-enabled/100-api.sharedmobility.ai.conf | |
sudo pico -w /etc/apache2/sites-enabled/100-api.sharedmobility.ai-le-ssl.conf | |
sudo systemctl restart apache2 | |
# Certbot for TLS/SSL certificates | |
sudo apt-get install certbot python-certbot-apache | |
# Certbot in interactive mode => you have to enter the details. | |
sudo certbot --apache | |
sudo certbot renew --dry-run | |
# Check if certbot is on auto-schedule | |
sudo systemctl list-timers | |
# Install Node.js 12.x LTS release line | |
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - | |
sudo apt-get install -y nodejs | |
# Check your Node version | |
node --version | |
# Create a separate non-root node user | |
sudo groupadd --gid 2000 node | |
sudo useradd --uid 2000 --gid node --shell /bin/bash --create-home node | |
# Create app directory for node applications | |
sudo mkdir /usr/local/node-apps/ | |
sudo chown node /usr/local/node-apps/ | |
sudo chgrp node /usr/local/node-apps/ | |
sudo mkdir /var/log/node | |
sudo chown node /var/log/node/ | |
sudo chgrp node /var/log/node/ | |
# Install git | |
sudo apt-get install git | |
cd /usr/local/node-apps/ | |
# Clone the SharedMobility.ai repository as node user | |
sudo su node | |
git clone https://github.com/botic/sharedmobility-ai.git | |
exit | |
# Install dependencies | |
cd /usr/local/node-apps/sharedmobility-ai/web-api/ | |
sudo npm install --unsafe-perm=true --allow-root | |
sudo chown -R node node_modules/ | |
sudo chgrp -R node node_modules/ | |
# Install pm2 process manager | |
sudo npm install -g pm2 | |
sudo pm2 startup systemd -u node --hp /home/node | |
# You find the apps.json in the full gist | |
sudo pico /etc/pm2/apps.json | |
sudo -u node pm2 start /etc/pm2/apps.json | |
sudo -u node pm2 save | |
# Everything should be fine. | |
# Try to reboot and check if everything is running after. | |
sudo shutdown -r +1 | |
# To end for your session in a proper way, sign-out asap ... | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment