Ubuntu 10.04 LTS 64bit

by visnup
27 deployments · 9 still active · last rev. 5 years ago

node, mongodb, ree, apache

Compatible with: No distros currently supported
						#!/bin/bash
# http://dpritchett.posterous.com/get-up-and-running-with-nodejs-on-your-own-am
# http://increaseyourgeek.wordpress.com/2010/08/18/install-node-js-without-using-sudo/
# http://fortnightlabs.posterous.com/

# <UDF name="node_process" Label="node app name" default="" example="monitaur" />
# <UDF name="ree" Label="ruby enterprise edition version" default="ruby-enterprise-1.8.7-2010.02" example="ruby-enterprise-1.8.7-2010.02" />
# <UDF name="authorized_keys" Label="url to grab authorized keys" default="" example="https://gist.github.com/raw/15a957952aa90eab4a27/1f06d60655d54dbe525d489f39e4fedbf163377c/authorized_keys" />

# create the app user
mkdir /u
useradd -U -d /u/apps -s /bin/bash -m -r app

# set-up ssh
mkdir /root/.ssh
curl $AUTHORIZED_KEYS >> /root/.ssh/authorized_keys
chmod 0700 /root/.ssh

mkdir /u/apps/.ssh
curl $AUTHORIZED_KEYS >> /u/apps/.ssh/authorized_keys
chmod 0700 /u/apps/.ssh
chown -R app:app /u/apps/.ssh

# add mongodb repo
cat <<END >> /etc/apt/sources.list

deb http://downloads.mongodb.org/distros/ubuntu 10.4 10gen
END
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

# update to latest
apt-get update -y
apt-get upgrade -y

# install software
apt-get install -y mongodb-stable redis-server monit

# install dependencies
apt-get install -y build-essential curl libssl-dev libreadline5-dev git-core

# install REE
cd /tmp
curl -o $REE.tar.gz http://rubyforge.org/frs/download.php/71096/$REE.tar.gz/noredirect
tar xzf $REE.tar.gz
$REE/installer -a /opt/$REE
PATH=/opt/$REE/bin:$PATH
echo "PATH=$PATH" > /etc/environment

# install passenger
apt-get install -y libcurl4-openssl-dev apache2-mpm-prefork apache2-prefork-dev libapr1-dev libaprutil1-dev
passenger-install-apache2-module -a
cd /etc/apache2/mods-available
passenger-install-apache2-module --snippet | head -1 > passenger.load
passenger-install-apache2-module --snippet | tail -2 > passenger.conf
a2enmod passenger

# configure apache
a2dissite default
cd /etc/apache2/sites-available
cat <<END > $NODE_PROCESS
  <VirtualHost *:80>
    ServerName dev.monitaur.net
    DocumentRoot /u/apps/monitaur/current/public
    <Directory /u/apps/monitaur/current/public>
      AllowOverride all
      Options -MultiViews
    </Directory>
  </VirtualHost>
END
a2ensite $NODE_PROCESS
/etc/init.d/apache2 restart

# rails default env
cat <<END >> /u/apps/.profile

export RAILS_ENV=production
export NODE_ENV=production
END

# create the upstart script
cat <<END > /etc/init/$NODE_PROCESS.conf
description "$NODE_PROCESS"
author "visnup"

start on startup
stop on shutdown

script
  exec sudo NODE_ENV=production /u/apps/local/bin/node /u/apps/$NODE_PROCESS/current/node/server.js >> /u/apps/$NODE_PROCESS/current/log/node.log 2>&1
end script
END

# let the app user start / stop / restart the process
cat <<END >> /etc/sudoers

app     ALL=NOPASSWD: /sbin/restart $NODE_PROCESS
app     ALL=NOPASSWD: /sbin/stop $NODE_PROCESS
app     ALL=NOPASSWD: /sbin/start $NODE_PROCESS
END


# login app
cat <<END > /tmp/AsApp.sh
# setup space for node
export PREFIX=/u/apps/local
mkdir \$PREFIX
perl -i -pe 's/bin/local\/bin/g' /u/apps/.profile

# install node latest
cd /tmp
NODE_URL="http://nodejs.org/dist/node-latest.tar.gz"
wget $NODE_URL
tar xzf node-latest.tar.gz
cd node-v*
./configure
make && make install

# install npm
export PATH=/u/apps/local/bin:\$PATH
curl http://npmjs.org/install.sh | sh
END

sudo -u app sh /tmp/AsApp.sh