adamhjk (owner)

Revisions

gist: 224643 Download_button fork
public
Public Clone URL: git://gist.github.com/224643.git
Embed All Files: show embed
solr_boootstrap.rb #
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
          solr_base = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "solr"))
 
          # Create the Jetty container
          unless File.directory?(Chef::Config[:solr_jetty_path])
            Chef::Log.warn("Initializing the Jetty container")
            solr_jetty_dir = Chef::Resource::Directory.new(Chef::Config[:solr_jetty_path], nil, c.node)
            solr_jetty_dir.recursive(true)
            solr_jetty_dir.run_action(:create)
            solr_jetty_untar = Chef::Resource::Execute.new("untar_jetty", nil, c.node)
            solr_jetty_untar.command("tar zxvf #{File.join(solr_base, 'solr-jetty.tar.gz')}")
            solr_jetty_untar.cwd(Chef::Config[:solr_jetty_path])
            solr_jetty_untar.run_action(:run)
          end
 
          # Create the solr home
          unless File.directory?(Chef::Config[:solr_home_path])
            Chef::Log.warn("Initializing Solr home directory")
            solr_home_dir = Chef::Resource::Directory.new(Chef::Config[:solr_home_path], nil, c.node)
            solr_home_dir.recursive(true)
            solr_home_dir.run_action(:create)
            solr_jetty_untar = Chef::Resource::Execute.new("untar_solr_home", nil, c.node)
            solr_jetty_untar.command("tar zxvf #{File.join(solr_base, 'solr-home.tar.gz')}")
            solr_jetty_untar.cwd(Chef::Config[:solr_home_path])
            solr_jetty_untar.run_action(:run)
          end
 
          # Create the solr data path
          unless File.directory?(Chef::Config[:solr_data_path])
            Chef::Log.warn("Initializing Solr data directory")
            solr_data_dir = Chef::Resource::Directory.new(Chef::Config[:solr_data_path], nil, c.node)
            solr_data_dir.recursive(true)
            solr_data_dir.run_action(:create)
          end
        end
 
        def run_application
          if Chef::Config[:daemonize]
            Chef::Daemon.daemonize("chef-solr")
          end
          Dir.chdir(Chef::Config[:solr_jetty_path]) do
            command = "java -Xmx#{Chef::Config[:solr_heap_size]} -Xms#{Chef::Config[:solr_heap_size]}"
            command << " -Dsolr.solr.data=#{Chef::Config[:solr_data_path]}"
            command << " -Dsolr.solr.home=#{Chef::Config[:solr_home_path]}"
            command << " #{Chef::Config[:solr_java_opts]}" if Chef::Config[:solr_java_opts]
            command << " -jar #{File.join(Chef::Config[:solr_jetty_path], 'start.jar')}"
            Chef::Log.info("Starting Solr with #{command}")
            Kernel.exec(command)
 
          end