Skip to content

Instantly share code, notes, and snippets.

@YannMjl
Last active November 4, 2022 16:26
Show Gist options
  • Save YannMjl/dbd237ada6f1f12f8ddda9e011afb778 to your computer and use it in GitHub Desktop.
Save YannMjl/dbd237ada6f1f12f8ddda9e011afb778 to your computer and use it in GitHub Desktop.
Run a nodejs app using PM2 from a script
! /bin/sh
# -----------------------------------------------------------------------*
# use this block when dveelopement your app locally on your laptop
# uncomment this section for local host testing only.
# Make surre to comment this out before pushing the code
# to your source code management repo
# export HOME=./
# node=$HOME
# -----------------------------------------------------------------------*
# you can add configuration for your Linux server hoting node setup
# Comment this block when testing locally
# make sure to uncomment this section before pusshing code
# here's an example of my setup:
export HOME=/opt/webapps/apps/myApp
log=$HOME/log
out=$log/myApp-out.log
err=$log/myApp-err.log
node=$HOME/lib/node
# -----------------------------------------------------------------------*
# runnig the app using pm2
# -----------------------------------------------------------------------*
cd $node
case $# in 1)
case "$1" in
start)
pm2 start ecosystem.config.js --env development
exit
;;
status)
pm2 list
exit
;;
stop)
pm2 stop "app"
exit
;;
delete)
pm2 delete "app"
exit
;;
log)
pm2 log
exit
;;
restart)
pm2 restart ecosystem.config.js --env development
exit
;;
esac
esac
echo "Usage: `basename \"$0\"` { start | status | stop | delete | log | restart }"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment