Skip to content

Instantly share code, notes, and snippets.

@AstroTom
Created May 29, 2018 15:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AstroTom/a30d6031ce8a4d89d6757621da45f1e3 to your computer and use it in GitHub Desktop.
Save AstroTom/a30d6031ce8a4d89d6757621da45f1e3 to your computer and use it in GitHub Desktop.
live-server startup script to be installed in /etc/init.d
#!/bin/sh
# May 2018
# removed iptables and just run directly on port 443
# added RNT_ENV
#
#
# read in wishtrip config file for value of RNT_ENV etc
#
RNT_CONFIG_FILE=/etc/rnt.conf
if [ -s $RNT_CONFIG_FILE ]; then
. $RNT_CONFIG_FILE
fi
# test $RNT_ENV
[ -z "$RNT_ENV" ] && (echo >&2 "Variable is unset"; logger -t wishtrip "$0: RNT_ENV is unset, aborting";exit 1)
# for Live
case $RNT_ENV in
prd)
NODE_ENV=PROD
;;
stg)
NODE_ENV=STAGING
;;
*)
# default
NODE_ENV=$RNT_ENV
;;
esac
#echo "RNT_ENV IS $RNT_ENV"
#echo "NODE_ENV IS $NODE_ENV"
# set variables for Live server
export NODE_ENV
export PORT=443
export DEBUG=*,-express*,-socket*,-engine*,-compression,-ioredis*,-send,-node-stringprep,-body-parser:*,-morgan
SERVER_DIR=/opt/webservers/live-server
case "$1" in
start)
#logger "Configuring iptables "
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443
logger "Running live server with forever"
exec forever --sourceDir=$SERVER_DIR -l /var/log/forever.log -a -o /var/log/live-out.log -e /var/log/live-err.log start bin/www
;;
stop)
logger "Stopping live server"
#iptables -t nat -F
#iptables -t nat -X
uid=$(forever list | grep bin/www | cut -c24-27)
exec forever stop $uid
;;
restart)
#iptables -t nat -F
#iptables -t nat -X
uid=$(forever list | grep bin/www | cut -c24-27)
exec forever stop $uid
#logger "Configuring iptables "
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443
logger "Running live server with forever"
exec forever --sourceDir=$SERVER_DIR -l /var/log/forever.log -a -o /var/log/live-out.log -e /var/log/live-err.log start bin/www
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment