Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sails app production stage (Ubuntu 14+)
Follow the instructions
Depends on :
git setup,nodejs,variables
$ cd /etc/init/
$ touch $APP_HOSTNAME.conf
$ nano $APP_HOSTNAME.conf
===========================================================================
# Upstart job definition for www.dizymart.com
# uncomment for debug
# debug
description "$APP_HOSTNAME"
author "$APP_AUTHOR"
# start the service when system starts
start on runlevel [2345]
# stop the service when system is shutdown
stop on runlevel [06]
# prepare the environment
# Create directories for logging and process management
# Change ownership to the user running the process
pre-start script
mkdir -p /var/opt/node
mkdir -p /var/opt/node/log
mkdir -p /var/opt/node/run
chown -R $APP_AUTHOR:$APP_AUTHOR /var/opt/node
end script
# if the process quits unexpectedly, trigger a respawn
respawn
# Global Vars
env NODE_ENV=production
env PORT=3000
# start the process
exec start-stop-daemon --start --chuid $APP_AUTHOR --make-pidfile --pidfile /var/opt/node/run/$APP_HOSTNAME.pid --exec /usr/bin/node -- $APP_PATH/$APP_HOSTNAME/app.js >> /var/opt/node/log/$APP_HOSTNAME.log 2>&1
===========================================================================
$ sudo visudo // add at the bottom
===========================================================================
# Allow web app managers to start, stop and restart web app services without requiring a password
# needed for managing services in git hooks post-receive
WEB_APP_MANAGER ALL = NOPASSWD: /sbin/start $APP_HOSTNAME, /sbin/stop/$APP_HOSTNAME, /sbin/restart $APP_HOSTNAME
===========================================================================
#!/bin/sh
error_exit (){
echo "$1" 1>&2
exit 1
}
echo -n "Enter commit message":
read commit_message
cd /sites/myproject || error_exit "error changing directory!. now exiting..."
git add -A
git commit -m "$commit_message"
git push origin master
echo "Do you wish to deploy to production server?"
select yn in "Yes" "No"; do
case $yn in
Yes ) git push production master; break;;
No ) exit;;
esac
done
Depends on :
LC_check,variables,nodejs
$ mkdir $CODE_PATH/$APP_HOSTNAME // production code
$ mkdir $REPO_PATH/$APP_HOSTNAME.git // production git repository
$ cd $REPO_PATH/$APP_HOSTNAME.git
$ git init --bare
$ cd $REPO_PATH/$APP_HOSTNAME.git/hooks
$ touch post-receive
$ nano post-receive
================================================================================================
#!/bin/sh
error_exit (){
echo "$1" 1>&2
exit 1
}
git --work-tree=$CODE_PATH/$APP_HOSTNAME --git-dir=$REPO_PATH/$APP_HOSTNAME.git checkout -f
cd $CODE_PATH/$APP_HOSTNAME || error_exit "error changing directory!. now exiting..."
npm install || error_exit "error running npm install! now exiting ..."
npm prune || error_exit "error running npm purge! now exiting ..."
bower install || error_exit "error running bower install! now exiting ..."
bower prune || error_exit "error running bower install! now exiting ..."
# restart service
/sbin/restart $APP_HOSTNAME
================================================================================================
$ locale //output must not have empty records
// Fix:
// Check that you have the locales package installed
$ dpkg -l locales
// The last line is the important one: if it starts with ii, the package is installed, and everything is fine. If not, install it.
$ apt-get install locales
$ dpkg-reconfigure locales
// add at the end of
$ nano ~/.bash
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
// add at the end of
$ nano ~/.profile
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
source ~/.bashrc
Depends on :
nodejs, variables
$ cd some/dir/
$ sails start $APP_NAME
$ cd $APP_NAME
$ git init
$ git remote add production ssh://$SSH_USER@$SSH_IP/$REPO_PATH/$APP_HOSTNAME.git
// let's push all the code now
$ git add -A
$ git commit -m 'Initial App Commit'
$ git push -u origin --all # pushes up the repo and its refs for the first time
$ git push -u origin --tags # pushes up any tags
$ git push production master
Depends on :
LC_check,variables
$ apt-get install nginx
$ touch /etc/sites-available/$APP_HOSTNAME.conf
$ nano /etc/sites-available/$APP_HOSTNAME.conf
========================================================================
upstream $APP_NAME {
server 127.0.0.1:3000;
keepalive 64;
}
server {
listen 80;
server_name $APP_HOSTNAME www.$APP_HOSTNAME;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://$APP_NAME/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
========================================================================
$ cp /etc/sites-available/$APP_HOSTNAME.conf /etc/sites-enabled/$APP_HOSTNAME.conf
$ service nginx restart
Depends on :
LC_check
$ apt-get install --yes build-essential
$ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
$ apt-get install -y nodejs
$ npm install -g bower
$ npm install -g grunt
$ npm install -g sails
APP_NAME : www_app
APP_AUTHOR : funyx
APP_HOSTNAME : app.com
CODE_PATH : /var/www
REPO_PATH : /var/repo
@jayvi

This comment has been minimized.

Copy link

commented Nov 8, 2015

nice :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.