`
iandaicsu
  • 浏览: 52023 次
社区版块
存档分类
最新评论

nginx +unicorn + gollum 搭建 wiki

 
阅读更多

STEP 1 创建一个新用户,用户文件夹权限755

 

STEP 2 检查现有系统,关闭Apache的httpd服务,如果有

 

STEP 3 更新yum,安装gollum要求的gem

      --->https://github.com/gollum/gollum

 

STEP 4 新建一个wiki directory, 并 git init . & commit.  Gollum只会读取commit之后的文件。

 

STEP 5 配置 Nginx   /etc/nginx/conf.d/default.conf 

 

 

location / {   # 反向代理配置,连接localhost:4567的web服务器  
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    proxy_set_header Host $http_host;  
    proxy_pass http://localhost:4567;  
    }  

 

 

STEP 6  配置Unicorn config。Gollum 使用 unicorn 做为 app server的配置,也可以直接使用默认WEBric 做为server。

 

 

# unicron.conf
worker_processes  2
working_directory '/home/gollum'
#listen '/tmp/gollum.sock', :backlog => 1
listen 4567, :tcp_nopush => true               # 监听 4567 端口
timeout 10
pid '/tmp/gollum.pid'                          # process id 存放文件夹
preload_app  true
stderr_path '/var/log/gollum/unicorn.log'

before_fork do |server, worker|
  old_pid = "#{server.config[:pid]}.oldbin"
  if old_pid != server.pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end

  sleep 1
end

after_fork do |server, worker|
  addr = "127.0.0.1:#{4567 + worker.nr}"
  server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => 1)
end

 

 

STEP 7 配置 wiki app 的 config.ru

 

 

#!/usr/bin/env ruby
require 'rubygems'
require 'gollum/app'

gollum_path = File.expand_path('/home/gollum/wiki') # CHANGE THIS TO POINT TO YOUR OWN WIKI REPO
Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown) # set your favorite markup language
Precious::App.set(:wiki_options, {:universal_toc => false})
run Precious::App

 

 

 

STEP  8 执行命令start server

 

unicorn -D -c /home/gollum/unicorn.conf /home/gollum/config.ru

 

 

STEP 9 配置 unicorn的init script

 

#!/bin/sh
# chkconfig: - 85 15
# description: unicorn

set -e

TIMEOUT=${TIMEOUT-60}
APP_NAME=gollum
APP_ROOT=/home/gollum/gollum
PID=/tmp/gollum.pid
CMD="cd $APP_ROOT && bundle exec unicorn -D -c /home/gollum/unicorn.conf /home/gollum/config.ru"
USER=gollum
action="$1"
set -u

old_pid="$PID.oldbin"

cd $APP_ROOT || exit 1


sig () {
        test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
  test -s $old_pid && kill -$1 `cat $old_pid`
}

workersig () {
        workerpid="/tmp/unicorn.$APP_NAME.$2.pid"
        test -s "$workerpid" && kill -$1 `cat $workerpid`
}

case $action in
start)
  sig 0 && echo >&2 "Already running" && exit 0
  su - $USER -c "$CMD"
  ;;
stop)
  sig QUIT && exit 0
  echo >&2 "Not running"
  ;;
force-stop)
  sig TERM && exit 0
  echo >&2 "Not running"
  ;;
restart|reload)
  sig HUP && echo reloaded OK && exit 0
  echo >&2 "Couldn't reload, starting '$CMD' instead"
  su - $USER -c "$CMD"
  ;;
upgrade)
  if sig USR2 && sleep 20 && sig 0 && oldsig QUIT
  then
    n=$TIMEOUT
    while test -s $old_pid && test $n -ge 0
    do
      printf '.' && sleep 1 && n=$(( $n - 1 ))
    done
    echo

    if test $n -lt 0 && test -s $old_pid
    then
      echo >&2 "$old_pid still exists after $TIMEOUT seconds"
      exit 1
    fi
    exit 0
  fi
  echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  su - $USER -c "$CMD"
  ;;
kill_worker)
  workersig QUIT $2 && exit 0
  echo >&2 "Worker not running"
  ;;

reopen-logs)
  sig USR1
  ;;
*)
  echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
  exit 1
  ;;
esac

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics