Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 18 commits
  • 17 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 09, 2012
@danielbeardsley danielbeardsley Load external wompt.conf capistrano config file 58746fc
@danielbeardsley danielbeardsley Use correct repo in deploy config 135475a
@danielbeardsley danielbeardsley Add wompt.conf.example
And move some config options to it
f0c7a8c
Commits on Jul 24, 2012
@danielbeardsley danielbeardsley Deploy: allow custom monit config location 388508f
@danielbeardsley danielbeardsley Deploy: have deploy:cold do more of the setup 705d5e3
@danielbeardsley danielbeardsley Deploy: use random file name for temp files a7671f3
@danielbeardsley danielbeardsley run script: fix some documentation 2c6c134
Commits on Jul 29, 2012
@danielbeardsley danielbeardsley Have wompt write out it's own pid file
Getting the PID in the init.d script is fairly problematic, this is WAY easier.
4075f56
@danielbeardsley danielbeardsley Deploy: Use a REAL init.d script
* Allow customization of nodejs binary location
* remove old run_script
* use the traditional /sbin/service to launch wompt
334e01d
@danielbeardsley danielbeardsley Deploy: Simplify init.d script using bash functions
Bash has all these nice built-in functions for pis and status stuff, let's
use them!
b59bd23
Commits on Jul 30, 2012
@danielbeardsley danielbeardsley Deploy: add real init.d script for wompt_auth
* Remove mongodb dependency in monit config cause mongodb is
  left up to the user to install / monitor
* Remove old run script for wompt_auth
cf5b2e5
@danielbeardsley danielbeardsley Deploy: use login shell for capistrano commands
On the server we were deploying to, the default non-interactive
environment for shell commands was bare. Using a login
shell ensures that at least .bashrc is loaded.
e03e059
@danielbeardsley danielbeardsley Remove config for mongodb
Monitoring / installing / restarting mongodb is now in the hands of the
sysadmin, not wompt's.
2d8cfcc
@danielbeardsley danielbeardsley Deploy: use local copy of init.d script
for starting wompt, instead of relying on /sbin/service
c87cdc5
@danielbeardsley danielbeardsley Deploy: spice up the wompt.conf.example
Give it a nice header, a task override and explain most of the
variables.
6124d70
@danielbeardsley danielbeardsley More generic node executable path 2702b85
@danielbeardsley danielbeardsley README: update to reflect setup changes
Don't bother explaining how to install node and mongodb,
that is now left up to the user.
07d8029
@danielbeardsley danielbeardsley Merge branch 'new-initd-scripts'
* New init.d scripts / monit config
* Drop all mongddb related stuff
   * The user is responsible for maintaining / installng it,
     not wompt
* Add an external configuration file

Conflicts:
	config/deploy.rb
16b3799
View
3  .gitignore
@@ -5,3 +5,6 @@
.*
# All tilde ~ files (most vim temp files)
*~
+
+# User-supplied config file
+wompt.conf
View
35 README.md
@@ -1,38 +1,35 @@
# Wompt.com Readme #
## Installation ##
-### Node 0.6 ###
- git clone https://github.com/ry/node.git
- cd node
- git checkout v0.6.5
- ./configure
- make
- make install
-
-### MongoDB ###
- wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.4.tgz
- tar -xzf mongodb-linux-i686-2.0.4.tgz
- mv mongodb-linux-i686-2.0.4.tgz /someplace/in/your/path
+### Requirements ###
+ * node.js - v0.6.x
+ * ruby - v1.9
+ * rubygems
+ * bundler (gem)
+ * mongodb
### Wompt ###
git clone git@github.com:Wompt/wompt.com.git
cd wompt.com
- git submodule update --init
+ git submodule update --init --recursive
### Wompt authentication server ###
cd wompt.com/authentication
- gem install bundler
- bundle
+ bundle install
-### Start in dev mode ###
-#### MongoDB ####
- mongod
+### Start in development Mode ###
#### Wompt authentication server ####
cd authentication
bundle exec rackup
#### Wompt ####
node nodejs/server.js
+### Deployment ###
+### Install Capistrano (dev machine) ###
+ gem install capistrano
+
+### Setup for deployment ###
+
### Local Development ###
#### Offline mode ####
node nodejs/server.js -offline
@@ -87,4 +84,4 @@ This specifies all the various settings for the application: db name, constants,
file locations, port numbers, ... All of these are loaded from the files in
`/nodejs/environment` and `/authentication/config`. Settings from the default
environment are deep-merged with the application environment specified in the
-Deployment Environment config.
+Deployment Environment config.
View
15 config/config_files.rb
@@ -1,7 +1,7 @@
namespace :deploy do
- desc "save the local version of the run scripts to the server"
- task :send_run_scripts, :roles => :app do
- Dir.glob('config/run_scripts/*').each do |file|
+ desc "save the local version of the init.d scripts to the server"
+ task :send_initd_scripts, :roles => :app do
+ Dir.glob('config/init.d/*').each do |file|
dest = "#{shared_path}/#{File.basename(file)}"
process_erb_file_and_upload file, :destination => dest
run "chmod a+x #{dest}"
@@ -11,7 +11,7 @@
desc "Create symlinks in /etc/monit to the monit files in the deployed app"
task "symlink_monit_config" do
if deployment == 'production'
- run "#{try_sudo :as => 'root'} ln -f -s #{current_path}/config/monit/* /etc/monit/"
+ run "#{try_sudo} ln -f -s #{current_path}/config/monit/* #{monit_config_location}"
else
logger.info "Skipping monit config because this is not the live production app"
end
@@ -22,22 +22,21 @@
if deployment == 'production'
process_erb_file_and_upload('config/monit/wompt')
process_erb_file_and_upload('config/monit/wompt_auth')
- process_erb_file_and_upload('config/monit/mongodb')
else
logger.info "Skipping monit config because this is not the live production app"
end
end
def process_erb_file_and_upload filepath, opt={}
- remote_tempfile = "/tmp/#{File.basename(filepath)}"
+ remote_tempfile = "/tmp/#{File.basename(filepath)}." + rand(100000).to_s;
file = File.read(filepath)
processed = ERB.new(file).result(binding)
put processed, remote_tempfile
dest = opt[:destination] || (current_path + "/" + filepath)
- run "#{try_sudo :as => 'root'} mv #{remote_tempfile} #{dest}"
+ run "mv #{remote_tempfile} #{dest}"
end
end
after 'deploy:update', 'deploy:update_monit_config'
-after 'deploy:update', 'deploy:send_run_scripts'
+after 'deploy:update', 'deploy:send_initd_scripts'
after 'deploy:cold', 'deploy:symlink_monit_config'
View
21 config/deploy.rb
@@ -1,24 +1,27 @@
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
set :application, "wompt"
-set :user, "ubuntu"
-set :host, "wompt.com"
set :scm, :git
set :repository, "git@github.com:Wompt/wompt.com.git"
set :git_enable_submodules, true
set :deploy_via, :remote_cache
-
-role :app, host
-
set :use_sudo, true
-set :admin_runner, 'ubuntu'
set :normalize_asset_timestamps, false
set :copy_exclude, [".git"]
+set :monit_config_location, "/etc/monit/"
+
+# Node settings
+set :node_path, "/usr/bin/node"
default_run_options[:pty] = true
+# Use a login shell when executing commands so that
+# .bashrc and .bash_profile are loaded.
+set :default_shell, "sh -l"
+
+
task :production do
# :deployment variable should match task name
set :deployment, 'production'
@@ -29,6 +32,12 @@
find_and_execute_task("deploy:tags:schedule_creation")
end
+if File.exists?("wompt.conf")
+ load 'wompt.conf'
+else
+ $stderr.puts "No deployment configuration file found. Copy wompt.conf.example to wompt.conf"
+end
+
load 'config/tasks'
load 'config/config_files'
load 'config/deploy_tags'
View
2  config/gems.rb
@@ -1,5 +1,7 @@
namespace :deploy do
namespace :gems do
+ after 'deploy:cold', 'deploy:gems:install'
+
desc "Deploy and install missing ruby gem dependencies on the server"
task :default, :roles => :app do
after 'deploy:update', 'deploy:gems:install'
View
67 config/init.d/wompt
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+#
+# chkconfig: 35 99 99
+#
+
+. /etc/rc.d/init.d/functions
+
+USER="<%= user %>"
+
+APP="wompt"
+NODE="<%= node_path %>"
+SERVER="<%= current_path %>/nodejs/server.js"
+ERR_LOG="<%= shared_path %>/log/wompt.error.log"
+LOG="<%= shared_path %>/log/wompt.log"
+NODE_ENV="<%= application_environment %>"
+PID_FILE="<%= shared_path %>/pids/wompt.pid"
+
+do_start()
+{
+ PID=`cat $PID_FILE 2>/dev/null`
+
+ if [ "$PID" != "0" ] &&
+ [ "$PID" != "" ] &&
+ checkpid "$PID"; then
+ do_status
+ echo_failure
+ echo
+ RETVAL=1
+ else
+ echo -n $"Starting $APP: "
+ runuser -l "$USER" -c "NODE_ENV=$NODE_ENV $NODE $SERVER 2>>$ERR_LOG >>$LOG &" && echo_success || echo_failure
+ RETVAL=$?
+ echo
+ fi
+}
+do_stop()
+{
+ echo -n $"Stopping $APP: "
+ killproc -p $PID_FILE $APP
+ echo
+}
+do_status()
+{
+ status -p $PID_FILE $APP
+}
+
+case "$1" in
+ start)
+ do_start
+ ;;
+ stop)
+ do_stop
+ ;;
+ restart)
+ do_stop
+ do_start
+ ;;
+ status)
+ do_status
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ RETVAL=1
+esac
+
+exit $RETVAL
View
68 config/init.d/wompt_auth
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+#
+# chkconfig: 35 99 99
+#
+
+. /etc/rc.d/init.d/functions
+
+USER="<%= user %>"
+
+APP="wompt_auth"
+NODE="<%= node_path %>"
+SERVER_DIR="<%= current_path %>/authentication"
+SERVER="config.ru"
+ERR_LOG="<%= shared_path %>/log/wompt_auth.error.log"
+LOG="<%= shared_path %>/log/wompt_auth.log"
+APP_ENV="<%= application_environment %>"
+PID_FILE="<%= shared_path %>/pids/wompt_auth.pid"
+
+do_start()
+{
+ PID=`cat $PID_FILE 2>/dev/null`
+
+ if [ "$PID" != "0" ] &&
+ [ "$PID" != "" ] &&
+ checkpid "$PID"; then
+ do_status
+ echo_failure
+ echo
+ RETVAL=1
+ else
+ echo -n $"Starting $APP: "
+ runuser -l "$USER" -c "cd $SERVER_DIR && bundle exec rackup --env $APP_ENV --pid $PID_FILE $SERVER 2>>$ERR_LOG >>$LOG &" && echo_success || echo_failure
+ RETVAL=$?
+ echo
+ fi
+}
+do_stop()
+{
+ echo -n $"Stopping $APP: "
+ killproc -p $PID_FILE $APP
+ echo
+}
+do_status()
+{
+ status -p $PID_FILE $APP
+}
+
+case "$1" in
+ start)
+ do_start
+ ;;
+ stop)
+ do_stop
+ ;;
+ restart)
+ do_stop
+ do_start
+ ;;
+ status)
+ do_status
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ RETVAL=1
+esac
+
+exit $RETVAL
View
9 config/monit/mongodb
@@ -1,9 +0,0 @@
-check process mongodb with pidfile /var/lib/mongodb/mongod.lock
- group database
- start program = "<%= shared_path %>/mongodb start" with timeout 3 seconds
- stop program = "<%= shared_path %>/mongodb stop" with timeout 5 seconds
- if failed host 127.0.0.1 port 28017 protocol http
- and request "/"
- with timeout 5 seconds
- then restart
- if 5 restarts within 5 cycles then timeout
View
4 config/monit/wompt
@@ -1,8 +1,8 @@
check process wompt
with pidfile <%= shared_path %>/pids/wompt.pid
depends on wompt_auth
- start "<%= shared_path %>/wompt start" with timeout 3 seconds # gives it 3 sec to start up
- stop "<%= shared_path %>/wompt stop" with timeout 1 seconds # gives it 1 sec to shut down
+ start "<%= shared_path %>/wompt start"
+ stop "<%= shared_path %>/wompt stop"
if failed host 127.0.0.1 port 16999 protocol HTTP
request /ok
with timeout 5 seconds
View
5 config/monit/wompt_auth
@@ -1,9 +1,8 @@
#TODO fill in this process monitor with memory or CPU usage constraints
check process wompt_auth
with pidfile <%= shared_path %>/pids/wompt_auth.pid
- depends on mongodb
- start "<%= shared_path %>/wompt_auth start" with timeout 10 seconds # gives it 10 sec to start up
- stop "<%= shared_path %>/wompt_auth stop" with timeout 2 seconds # gives it 3 sec to shut down
+ start "<%= shared_path %>/wompt_auth start"
+ stop "<%= shared_path %>/wompt_auth stop"
if failed host 127.0.0.1 port 9292 protocol HTTP
request /ok
with timeout 5 seconds
View
1  config/npm.rb
@@ -1,6 +1,7 @@
namespace :deploy do
namespace :npm do
after "deploy:update_code", "deploy:npm:create_symlinks"
+ after 'deploy:cold', 'deploy:npm:install'
desc "Deploy and install missing npm dependencies on the server"
task :default, :roles => :app do
View
12 config/run_scripts/mongodb
@@ -1,12 +0,0 @@
-#!/bin/sh
-# Mongodb
-
-case $1 in
- start)
- sudo -u mongodb /usr/bin/mongod --quiet --fork --dbpath /var/lib/mongodb/ --logpath /var/lib/mongodb/mongodb.log --logappend --bind_ip 127.0.0.1
- ;;
- stop)
- kill `cat /var/lib/mongodb/mongod.lock` ;;
- *)
- echo "usage: wompt {start|stop}" ;;
-esac
View
20 config/run_scripts/wompt
@@ -1,20 +0,0 @@
-#!/bin/sh
-# Wompt (<%= deployment %> server running in <%= application_environment %> mode)
-<%
-server_js = "#{current_path}/nodejs/server.js"
-env = application_environment
-log_file = "#{shared_path}/log/wompt"
-%>
-
-case $1 in
- start)
- # Node needs HOME to be set
- HOME="<%=current_path %>/nodejs"
- sudo echo $$ > <%=shared_path%>/pids/wompt.pid;
- exec sudo -u nodejs NODE_ENV=<%=env%> /usr/local/bin/node <%=server_js%> 2>><%=log_file%>.error.log >><%=log_file%>.log
- ;;
- stop)
- kill `cat <%=shared_path%>/pids/wompt.pid` ;;
- *)
- echo "usage: wompt {start|stop}" ;;
-esac
View
17 config/run_scripts/wompt_auth
@@ -1,17 +0,0 @@
-#!/bin/sh
-# Wompt Authentication (<%= deployment %> server running in <%= application_environment %> mode)
-
-case $1 in
- start)
- cd <%=current_path%>/authentication
- <%
- env = application_environment
- log_file = "#{shared_path}/log/wompt_auth"
- %>
- exec sudo -u ubuntu rackup --env <%=env%> --pid <%=shared_path%>/pids/wompt_auth.pid 2>><%=log_file%>.error.log 1>><%=log_file%>.log
- ;;
- stop)
- kill `cat <%=shared_path%>/pids/wompt_auth.pid` ;;
- *)
- echo "usage: wompt_auth {start|stop}" ;;
-esac
View
2  nodejs/environment/production.js
@@ -7,6 +7,8 @@ module.exports = {
, db_name: 'wompt_prod'
, minify_assets: true
, perform_caching: true
+ , pid_file: path.normalize(shared + "/pids/wompt.pid")
+
, hoptoad: {
apiKey: '2d12a5a4e55714b1d7a3fbae31c5e0ae'
, reportErrors: true
View
5 nodejs/server.js
@@ -1,6 +1,11 @@
require('./redirector');
var wompt = require("./lib/includes");
+if (wompt.env.pid_file) {
+ var fs = require('fs');
+ fs.writeFileSync(wompt.env.pid_file, process.pid);
+}
+
var app = new wompt.App({
config: wompt.env,
root: __dirname
View
33 wompt.conf.example
@@ -0,0 +1,33 @@
+# Example Capistrano Configuration
+# Override any aand all config from the capistrano ruby files
+# [config/*.rb -- though mostly config/deploy.rb]
+
+# Linux user
+set :user, "ubuntu"
+# The servers the application will run on
+role :app, "yourserver.com"
+# The git repo that should be cloned when deploying
+set :repository, "http://github.com/yourforkof/wompt.com"
+set :use_sudo, true
+
+# Override or add any tasks here that you need to,
+# Or remove this part entirely to use the defaults (see deploy.rb)
+task :production do
+ # :deployment variable should match task name
+ # (think: production / staging / ...)
+ set :deployment, 'production'
+
+ # Path to deploy directory on destination server
+ set :deploy_to, "/home/wompt/www/#{application}"
+ set :branch, "master"
+
+ # Only used one time during deploy:cold
+ set :monit_config_location, "/etc/monit.d/"
+
+ # environment string that is passed to the nodejs and auth apps at startup
+ set :application_environment, 'production'
+
+ # auto-git-tag on every deploy
+ find_and_execute_task("deploy:tags:schedule_creation")
+end
+

No commit comments for this range

Something went wrong with that request. Please try again.