Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

How to install on UBUNTU 12.04

hari prasad sure edited this page Apr 12, 2017 · 6 revisions

How to install NODE.JS + node-uptime + MONGODB on UBUNTU 12.04 LTS

https://github.com/fzaninotto/uptime/

Install build-essentials and update gcc to latest version(as of this writing gcc-6 is latest)

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-6 g++-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 40 --slave /usr/bin/g++ g++ /usr/bin/g++-6
sudo update-alternatives --config gcc(Choose gcc-6 version row number)

Install a current version of NODE.JS

wget https://nodejs.org/dist/v4.2.1/node-v4.2.1-linux-x64.tar.gz
cd /usr/local
tar --strip-components 1 -xzf /usr/save/node-v4.2.1-linux-x64.tar.gz
node -v
npm -v

Download and install current version of node-uptime

cd /opt
git clone https://github.com/fzaninotto/uptime.git node-uptime
cd node-uptime
sudo npm install

Configure MongoDB access for node-uptime

cd /opt/node-uptime
sudo nano config/default.yaml
    mongodb:
    server:   localhost
    database: uptime
    user:     username
    password:    passsword
    connectionString: mongodb://localhost/uptime

Install MongoDB

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
sudo echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-10gen

Creare a mongodb admin user = if you plan to use auth

http://docs.mongodb.org/manual/tutorial/add-user-administrator/

mongo
use admin
db.addUser( { user: "username", pwd: "password", roles: [ "userAdminAnyDatabase" ] } )

Install supervisord to autostart as a service node-uptime

sudo apt-get -yq install python-setuptools
sudo easy_install supervisor
sudo echo_supervisord_conf > /etc/supervisord.conf

Edit supervisord config and add node-uptime (add this to bottom of file)

sudo nano /etc/supervisord.conf

[program:node-uptime]
command=node app.js
numprocs=1
#root dir of node-uptime
directory=/opt/node-uptime
stdout_logfile=/var/log/node-uptime.log
stderr_logfile=/var/log/node-uptime_error.log 
autostart=true
autorestart=true

Create a supervisord deamon, add this to /etc/init.d/supervisord

sudo nano /etc/init.d/supervisord
#! /bin/bash -e

SUPERVISORD=/usr/local/bin/supervisord
PIDFILE=/tmp/supervisord.pid
OPTS="-c /etc/supervisord.conf"

test -x $SUPERVISORD || exit 0

. /lib/lsb/init-functions

export PATH="${PATH:+$PATH:}/usr/local/bin:/usr/sbin:/sbin"

case "$1" in
  start)
    log_begin_msg "Starting Supervisor daemon manager..."
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $SUPERVISORD -- $OPTS || log_end_msg 1
    log_end_msg 0
    ;;
  stop)
    log_begin_msg "Stopping Supervisor daemon manager..."
    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE || log_end_msg 1
    log_end_msg 0
    ;;

  restart|reload|force-reload)
    log_begin_msg "Restarting Supervisor daemon manager..."
    start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
    start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec $SUPERVISORD -- $OPTS || log_end_msg 1
    log_end_msg 0
    ;;

  *)
    log_success_msg "Usage: /etc/init.d/supervisor
{start|stop|reload|force-reload|restart}"
    exit 1
esac

exit 0

Make the supervisord daemon execute magically

sudo chmod +x /etc/init.d/supervisord
sudo update-rc.d supervisord defaults

Restart supervisord

sudo service supervisord restart

Manage node-uptime

sudo supervisorctl start|stop|restart node-uptime