Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
11 config/apache.conf
... ... @@ -1,11 +0,0 @@
1   -<VirtualHost *:80>
2   - ServerName molawson.com
3   - ServerAlias www.molawson.com
4   - DocumentRoot /srv/apps/molawson/current/public
5   - <Directory "/srv/apps/molawson/current/public">
6   - Options FollowSymLinks
7   - AllowOverride None
8   - Order allow,deny
9   - Allow from all
10   - </Directory>
11   -</VirtualHost>
24 config/deploy.rb
@@ -19,21 +19,21 @@
19 19 default_run_options[:pty] = true
20 20 ssh_options[:forward_agent] = true
21 21
22   -role :web, "198.74.62.226"
23   -role :app, "198.74.62.226"
24   -role :db, "198.74.62.226", :primary => true
  22 +role :web, "kirby.molawson.com"
  23 +role :app, "kirby.molawson.com"
  24 +role :db, "kirby.molawson.com", :primary => true
25 25
26 26
27 27 after "deploy", "deploy:cleanup" # keep only the last 5 releases
28 28
29 29 namespace :deploy do
30   - task :start do; end
31   - task :stop do; end
32   - task :restart, roles: :app, except: { :no_release => true } do
33   - run "touch #{deploy_to}/current/tmp/restart.txt"
  30 + %w[start stop restart].each do |command|
  31 + desc "#{command} unicorn server"
  32 + task command, roles: :app, except: {no_release: true} do
  33 + run "/etc/init.d/unicorn_#{application} #{command}"
  34 + end
34 35 end
35 36
36   -
37 37 task :create_config_files do
38 38 default_admin_login = <<-EOF
39 39 USERNAME: #{user}
@@ -94,10 +94,8 @@
94 94 end
95 95
96 96 task :setup_config, roles: :app do
97   - sudo "ln -nfs #{current_path}/config/apache.conf /etc/apache2/sites-available/#{application}"
98   - run "mkdir -p #{shared_path}/config"
99   - put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
100   - puts "Now edit the config files in #{shared_path}."
  97 + sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
  98 + sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
101 99 end
102 100 after "deploy:setup", "deploy:setup_config"
103 101
@@ -146,7 +144,7 @@
146 144 username: #{user}
147 145 password: #{password}
148 146 EOF
149   -
  147 +
150 148 db_config = ERB.new(default_template)
151 149
152 150 run "mkdir -p #{shared_path}/config"
27 config/nginx.conf
... ... @@ -0,0 +1,27 @@
  1 +upstream unicorn {
  2 + server unix:/tmp/unicorn.molawson.sock fail_timeout=0;
  3 +}
  4 +
  5 +server {
  6 + listen 80 default deferred;
  7 + # server_name example.com;
  8 + root /var/apps/molawson/current/public;
  9 +
  10 + location ^~ /assets/ {
  11 + gzip_static on;
  12 + expires max;
  13 + add_header Cache-Control public;
  14 + }
  15 +
  16 + try_files $uri/index.html $uri @unicorn;
  17 + location @unicorn {
  18 + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  19 + proxy_set_header Host $http_host;
  20 + proxy_redirect off;
  21 + proxy_pass http://unicorn;
  22 + }
  23 +
  24 + error_page 500 502 503 504 /500.html;
  25 + client_max_body_size 4G;
  26 + keepalive_timeout 10;
  27 +}
9 config/unicorn.rb
... ... @@ -0,0 +1,9 @@
  1 +root = "/var/apps/molawson/current"
  2 +working_directory root
  3 +pid "#{root}/tmp/pids/unicorn.pid"
  4 +stderr_path "#{root}/log/unicorn.log"
  5 +stdout_path "#{root}/log/unicorn.log"
  6 +
  7 +listen "/tmp/unicorn.molawson.sock"
  8 +worker_processes 2
  9 +timeout 30
84 config/unicorn_init.sh
... ... @@ -0,0 +1,84 @@
  1 +#!/bin/sh
  2 +### BEGIN INIT INFO
  3 +# Provides: unicorn
  4 +# Required-Start: $remote_fs $syslog
  5 +# Required-Stop: $remote_fs $syslog
  6 +# Default-Start: 2 3 4 5
  7 +# Default-Stop: 0 1 6
  8 +# Short-Description: Manage unicorn server
  9 +# Description: Start, stop, restart unicorn server for a specific application.
  10 +### END INIT INFO
  11 +set -e
  12 +
  13 +# Feel free to change any of the following variables for your app:
  14 +TIMEOUT=${TIMEOUT-60}
  15 +APP_ROOT=/var/apps/molawson/current
  16 +PID=$APP_ROOT/tmp/pids/unicorn.pid
  17 +CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
  18 +AS_USER=deploy
  19 +set -u
  20 +
  21 +OLD_PIN="$PID.oldbin"
  22 +
  23 +sig () {
  24 + test -s "$PID" && kill -$1 `cat $PID`
  25 +}
  26 +
  27 +oldsig () {
  28 + test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
  29 +}
  30 +
  31 +run () {
  32 + if [ "$(id -un)" = "$AS_USER" ]; then
  33 + eval $1
  34 + else
  35 + su -c "$1" - $AS_USER
  36 + fi
  37 +}
  38 +
  39 +case "$1" in
  40 +start)
  41 + sig 0 && echo >&2 "Already running" && exit 0
  42 + run "$CMD"
  43 + ;;
  44 +stop)
  45 + sig QUIT && exit 0
  46 + echo >&2 "Not running"
  47 + ;;
  48 +force-stop)
  49 + sig TERM && exit 0
  50 + echo >&2 "Not running"
  51 + ;;
  52 +restart|reload)
  53 + sig HUP && echo reloaded OK && exit 0
  54 + echo >&2 "Couldn't reload, starting '$CMD' instead"
  55 + run "$CMD"
  56 + ;;
  57 +upgrade)
  58 + if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
  59 + then
  60 + n=$TIMEOUT
  61 + while test -s $OLD_PIN && test $n -ge 0
  62 + do
  63 + printf '.' && sleep 1 && n=$(( $n - 1 ))
  64 + done
  65 + echo
  66 +
  67 + if test $n -lt 0 && test -s $OLD_PIN
  68 + then
  69 + echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
  70 + exit 1
  71 + fi
  72 + exit 0
  73 + fi
  74 + echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  75 + run "$CMD"
  76 + ;;
  77 +reopen-logs)
  78 + sig USR1
  79 + ;;
  80 +*)
  81 + echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
  82 + exit 1
  83 + ;;
  84 +esac

No commit comments for this range

Something went wrong with that request. Please try again.