Skip to content

Instantly share code, notes, and snippets.

@viperfx
Created June 22, 2014 18:48
Show Gist options
  • Save viperfx/cce17510e29b32229d33 to your computer and use it in GitHub Desktop.
Save viperfx/cce17510e29b32229d33 to your computer and use it in GitHub Desktop.

Revisions

  1. viperfx created this gist Jun 22, 2014.
    46 changes: 46 additions & 0 deletions server.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/bin/bash

    # APT Packages
    apt-get -y update
    apt-get install -y aptitude
    aptitude install -y unattended-upgrades
    aptitude install -y build-essential libssl-dev libexpat1-dev pkg-config
    aptitude install -y git-core nginx
    aptitude install -y monit

    # set up automatic security updates
    cat > /etc/apt/apt.conf.d/10periodic <<EOF
    APT::Periodic::Enable "1";
    APT::Periodic::Update-Package-Lists "1";
    APT::Periodic::Download-Upgradeable-Packages "1";
    APT::Periodic::AutocleanInterval "5";
    APT::Periodic::Unattended-Upgrade "1";
    APT::Periodic::RandomSleep "1800";
    EOF

    # nodejs
    wget wget http://nodejs.org/dist/v0.10.26/node-v0.10.26.tar.gz
    tar -zxvf node-v0.10.26.tar.gz
    pushd node-v0.10.26
    ./configure
    make
    make install
    popd
    rm -rf node-v0.10.26.tar.gz node-v0.10.26

    # npm
    curl http://npmjs.org/install.sh | sudo sh

    # Setup basic nginx proxy.
    unlink /etc/nginx/sites-available/default
    cat > /etc/nginx/sites-available/node_proxy.conf <<EOF
    server {
    listen 80;
    # proxy to node
    location / {
    proxy_pass http://127.0.0.1:3000/;
    }
    }
    EOF
    ln -s /etc/nginx/sites-available/node_proxy.conf /etc/nginx/sites-enabled/node_proxy.conf
    /etc/init.d/nginx restart
    14 changes: 14 additions & 0 deletions sitename.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!upstart
    #/etc/init/sitename.conf

    description "Sitename"

    start on (local-filesystems and net-device-up IFACE=eth0)
    stop on shutdown

    respawn # restart when job dies
    respawn limit 5 60 # give up restart after 5 respawns in 60 seconds

    script
    exec node /var/www/appname >> /var/www/appnamelogs/upstart.log 2>&1
    end script