Skip to content

Instantly share code, notes, and snippets.

@jldavid
Last active October 16, 2020 04:01
Show Gist options
  • Select an option

  • Save jldavid/aaa9a60d98c3a14f732a57f418536179 to your computer and use it in GitHub Desktop.

Select an option

Save jldavid/aaa9a60d98c3a14f732a57f418536179 to your computer and use it in GitHub Desktop.
Setting Up a Bitnami API

BITNAMI SETUP TUTORIAL

CONNECT TO BITNAMI MEAN STACK

chmod 400 YourPEM.pem
ssh -i YourPEM.pem ubuntu@yourserveraddress.amazonaws.com
ssh -i YourPEM.pem bitnami@serveripaddress

BITNAMI CREDENTIALS

  • cat bitnami_credentials

ADDING GITHUB CREDENTIALS TO BITNAMI INSTANCE

  • Do this in the same directory as the Node.js server.
git config credential.helper store
git push https://github.com/yourgithubrepo/yourrepo.git

CLONING SERVER CODE TO AWS

  • Log in the server using `ssh -i YourPEM.pem bitnami@serveripaddress
  • Create a folder called apps (mkdir apps) and enter the folder (cd apps)
  • Clone the code inside the folder (git clone https://github.com/yourgithubrepo/yourrepo.git)
  • Change permissions to make it Read Write Execute from server, Read Execute from outside (standard Web Server permissions - chmod 755 yourdirectory)
  • Install Node dependencies: npm install

UPDATING SERVER CODE

  • Clone the code on your computer (git clone https://github.com/yourgithubrepo/yourrepo.git)
  • Make modifications & commit your changes to Github (git add, git commit -m, git push)
  • Log in the server using ssh -i YourPEM.pem bitnami@youripaddress
  • Go to your api folder: cd apps/yourrepo
  • Pull in the changes from Github: git pull

STARTING THE SERVER

  • Log in using ssh -i YourPEM.pem bitnami@youripaddress
  • Go to your api folder: cd apps/yourrepo
  • Manually start the server on the selected port: node index.js

SERVING THE API USING APACHE

  • Edit the Apache conf file: nano "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
  • Add the following line to the configuration:
Include "/home/bitnami/apps/api/conf/httpd-prefix.conf"
  • Restart Apache using the following command: sudo /opt/bitnami/ctlscript.sh restart apache
  • Now navigating to your default Bitnami website will present the API instead of the default Apache website
  • If the API isn't up and running (node index.js), the server will return a 503 Service Unavailable HTTP Error.
  • You can view server running processes on your selected port using: netstat -tulnp | grep yourportnumber

APACHE CONTROL COMMANDS

  • sudo /opt/bitnami/ctlscript.sh restart apache
  • sudo /opt/bitnami/ctlscript.sh start
  • sudo /opt/bitnami/ctlscript.sh stop
  • sudo /opt/bitnami/ctlscript.sh restart

SETUP FOREVER TO GET THE API RUNNING CONTINUOUSLY

  • Forever is available by default on Bitnami
  • To start the API using forever, use the following command:
forever start --minUptime 1000 --spinSleepTime 1000 index.js
  • You will get the warnings for --minUptime and --spinSleepTime. Needs to be revisited after deployed on prod - may have cost implications as the service will continuously restart. Documentation: https://stackoverflow.com/a/37166482
  • To view Forever processes, type: forever list
  • You can kill a Forever process using the uid: forever stop 0
  • Sometimes Forever will misbehave, you might launch 2 or more instances of the API, or there may be other issues. In that case, you need to kill the lower level Node processes on the server.
  • To view all running Node processes: ps axl | grep node. The output will look something like this:
0  1000 21858 * ? 0:00 /opt/bitnami/nodejs/bin/.node.bin /opt/bitnami/nodejs/lib/node_modules/forever/bin/monitor index.js
0  1000 21864 21858 * ? 0:00 /opt/bitnami/nodejs/bin/.node.bin /home/bitnami/apps/yourrepo/index.js
0  1000 21963 21668 * 0:00 grep --color=auto node
  • kill 21858 will stop the process running your API /yourrepo/index.js

TAIL SUPPORT

  • To interactively view Node application and error logs, start the API using the following command: forever start -o app.log -e err.log --minUptime 1000 --spinSleepTime 1000 index.js
  • You can tail these logs using the following command: tail -f app.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment