jnewland (owner)

Revisions

  • baa80a jnewland Wed Sep 16 06:58:10 -0700 2009
gist: 188053 Download_button fork
public
Public Clone URL: git://gist.github.com/188053.git
Embed All Files: show embed
deploy.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
after "deploy:setup", "thinking_sphinx:shared_sphinx_folder"
after 'deploy:finalize_update', 'thinking_sphinx:symlink_indexes'
after 'deploy:restart', 'thinking_sphinx:restart'
 
namespace :thinking_sphinx do
  task :symlink_indexes, :roles => [:app] do
    run "ln -nfs #{shared_path}/db/sphinx #{latest_release}/db/sphinx"
  end
  task :restart do
    configure
    god.app.delayed_delta.stop
    god.app.searchd.restart
    god.app.delayed_delta.start
  end
end
 
require 'san_juan'
 
set :god_config_path, "/etc/god/god.conf"
 
san_juan.role :app, %w(delayed_delta searchd)
sphinx.god #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
God.watch do |w|
  w.name = "delayed_delta"
  w.group = "sphinx"
  w.interval = 30.seconds
  w.start = "rake -f #{RAILS_ROOT}/Rakefile thinking_sphinx:delayed_delta"
  w.env = { "RAILS_ENV" => "production"}
  w.uid = 'rails'
  w.gid = 'rails'
 
  # retart if memory gets too high
  w.transition(:up, :restart) do |on|
    on.condition(:memory_usage) do |c|
      c.above = 300.megabytes
      c.times = 2
    end
  end
 
  # determine the state on startup
  w.transition(:init, { true => :up, false => :start }) do |on|
    on.condition(:process_running) do |c|
      c.running = true
    end
  end
 
  # determine when process has finished starting
  w.transition([:start, :restart], :up) do |on|
    on.condition(:process_running) do |c|
      c.running = true
      c.interval = 5.seconds
    end
  
    # failsafe
    on.condition(:tries) do |c|
      c.times = 5
      c.transition = :start
      c.interval = 5.seconds
    end
  end
 
  # start if process is not running
  w.transition(:up, :start) do |on|
    on.condition(:process_running) do |c|
      c.running = false
    end
  end
end
God.watch do |w|
  w.name = "searchd"
  w.group = "sphinx"
  w.interval = 30.seconds
  w.start = "searchd --config #{RAILS_ROOT}/config/#{RAILS_ENV}.sphinx.conf"
  w.start_grace = 10.seconds
  w.stop = "searchd --config #{RAILS_ROOT}/config/#{RAILS_ENV}.sphinx.conf --stop"
  w.stop_grace = 10.seconds
  w.pid_file = "#{RAILS_ROOT}/log/searchd.#{RAILS_ENV}.pid"
  w.uid = 'rails'
  w.gid = 'rails'
 
  # retart if memory gets too high
  w.transition(:up, :restart) do |on|
    on.condition(:memory_usage) do |c|
      c.above = 300.megabytes
      c.times = 2
    end
  end
 
  # determine the state on startup
  w.transition(:init, { true => :up, false => :start }) do |on|
    on.condition(:process_running) do |c|
      c.running = true
    end
  end
 
  # determine when process has finished starting
  w.transition([:start, :restart], :up) do |on|
    on.condition(:process_running) do |c|
      c.running = true
      c.interval = 5.seconds
    end
  
    # failsafe
    on.condition(:tries) do |c|
      c.times = 5
      c.transition = :start
      c.interval = 5.seconds
    end
  end
 
  # start if process is not running
  w.transition(:up, :start) do |on|
    on.condition(:process_running) do |c|
      c.running = false
    end
  end
end