Created
June 30, 2012 19:11
-
-
Save STRML/3025133 to your computer and use it in GitHub Desktop.
A few useful files for running a nodejs server. I keep update-project.js in /root so when I ssh in I can just run it. my-project.conf runs the project as the user 'www-data', and so fixperms.sh makes sure the project folder is readable/writable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
T=/usr/local/mycompany/my-project | |
chown -R www-data:root $T | |
find $T -type d ! -perm 770 -print -exec chmod 770 {} \; | |
find $T -type f ! -perm 660 ! -name "*.sh" -print -exec chmod 660 {} \; | |
find $T -type f ! -perm 770 -name "*.sh" -print -exec chmod 770 {} \; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!upstart | |
description "Upstart script for running NodeJS" | |
author "STRML" | |
respawn | |
start on startup | |
stop on shutdown | |
script | |
exec > /tmp/my-project-upstart-log 2>&1 | |
export HOME="/usr/local/mycompany/my-project" | |
export MY_PROJECT_LOG="/var/log/node/my-project.log" | |
export NODE="/usr/bin/node" | |
export NODE_USER="www-data" | |
export NODE_ENV=production | |
export NODE_PATH="$HOME/lib" | |
export PROJECT_HOME=$HOME | |
sleep 5 | |
su -c 'authbind $NODE $PROJECT_HOME/server.js 2>&1 >> $MY_PROJECT_LOG' $NODE_USER | |
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require('cluster'); | |
var myproj = require('myproj'); | |
var myproj_opts = require('myproj_opts'); // uses 'opt' module available in NPM | |
var os = require('os'); | |
/** Ferris Bueller, you're my hero */ | |
var env = myproject.settings.environment; | |
if(env !== "local" && env !== "test"){ | |
if(cluster.isMaster){ | |
os.cpus().forEach(function(){ | |
cluster.fork(); | |
}); | |
console.log("API server listening on port %d", myproj_opts.port); | |
cluster.on('exit', function(worker) { | |
console.log('worker ' + worker.pid + ' died'); | |
cluster.fork(); | |
}); | |
} else { | |
require('./app.js').listen(myproj_opts.port); | |
} | |
} else { // don't cluster on local or test | |
require('./app.js').listen(myproj_opts.port); | |
console.log("API server listening on port %d", myproj_opts.port); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
D=`pwd` | |
cd /usr/local/mycompany/my-project | |
/usr/bin/git checkout master | |
/usr/bin/git fetch origin | |
/usr/bin/git reset --hard origin/master | |
npm install --unsafe-perm | |
~/fixperms.sh | |
restart my-project | |
cd $D | |
echo "Updated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment