-1

So far I've been using the following recipe for installing Solr 3.x on Tomcat 6:

package { 'openjdk-6-jdk' :
  ensure => installed,
}
package { 'solr-tomcat' :
  ensure => installed,
}

exec { 'tomcat-port':
  command => "sed -i.bak 's|port=\"8080\"|port=\"8983\"|g' /etc/tomcat6/server.xml",
  path => ["/bin", "/usr/bin"],
}

service { 'tomcat6' :
  ensure => running,
  require => Package['solr-tomcat'],
}

However I'd like to install Solr 4.x on Tomcat 7, but it seems Debian doesn't have appropriate packages for Solr (such as solr-tomcat).

I've so far Tomcat 7 working by:

package { [ 'tomcat7', 'tomcat7-admin' ]: ensure => installed, }
service { 'tomcat7' : ensure => running, }
exec { 'tomcat-port':
  command => "sed -i.bak 's|port=\"8080\"|port=\"8983\"|g' /etc/tomcat7/server.xml",
  path => ["/bin", "/usr/bin"],
}

But how do I install Solr 4.x?

kenorb
  • 5,943
  • 1
  • 44
  • 53

2 Answers2

2

You can create your own Debian package and host it in your own repository. Projects like FPM (https://github.com/jordansissel/fpm) help a lot here. Another option is to retrieve the Solr tarball from the project website and manage a series of exec statements to extract it into the webapps directory in your Tomcat install.

Joel E Salas
  • 5,562
  • 15
  • 25
1

The simplest way is to define exec, for example:

exec { "solr-download":
  command => "/usr/bin/wget http://archive.apache.org/dist/lucene/solr/4.9.1/solr-4.9.1.tgz && /bin/tar -xf solr-4.9.1.tgz"
  cwd => "/opt",
  creates => "/opt/solr-4.9.1.tgz",
}

For more flexible solution, you've to write a class (solr4-tomcat.pp), for example:

class solr {

  # variables
  $version = '4.10.4'
  $data_dir = "/opt/solr/data"
  $home_dir = "/opt/solr/home"

  $tomcat_version = "tomcat7"
  $tomcat_base = "/var/lib/${tomcat_version}"
  $tomcat_user = $operatingsystem ? {
    /RedHat|CentOS/ => "tomcat", 
    /Debian|Ubuntu/ => $tomcat_version,
  }

  # includes
  include solr::files

  class { 'tomcat': install_from_source => false }

  # Ensure Java libraries are installed
  package { "java":
    ensure => present,
    name => $operatingsystem ? {
      'Centos' => $operatingsystemrelease ? {
        '6.0' => "java-1.6.0-openjdk.$hardwaremodel",
         '*' => 'openjdk-7-jre',
      },
      /Debian|Ubuntu/ => 'openjdk-7-jre-headless',
    },
  }

  # Set port 8983 for Tomcat 7 and make sure it's running.
  tomcat::instance {'default': package_name => $tomcat_version} ->
    tomcat::service  {'default':
      service_name => 'tomcat7',
      service_ensure => 'running',
      use_jsvc => false, use_init => true,
# use_jsvc => true, java_home => "/usr/lib/jvm/java-7-openjdk-amd64",
    }->
    tomcat::config::server { $tomcat_version:
      catalina_base => $tomcat_base,
      port          => 8983,
    }

  class solr::files {

    # Ensure solr directories are present.
    file { 'home_dir':
      path => $solr::home_dir,
      ensure => directory,
      recurse => true,
    }
    file { 'data_dir':
      path => $solr::data_dir,
      ensure => directory,
      recurse => true,
      owner => $solr::tomcat_user,
      group => $solr::tomcat_user,
    }

    # Download and extract solr
    exec { "solr-extract":
      path    => ['/usr/bin', '/usr/sbin', '/bin'],
      command => "curl -s http://archive.apache.org/dist/lucene/solr/${solr::version}/solr-${solr::version}.tgz | tar zxf -",
      cwd => "/opt/solr",
      require => [File["data_dir"], File["home_dir"]],
      creates => "/opt/solr/solr-${solr::version}/dist/solr-${solr::version}.war",
    }
    # Logging setup for Tomcat.
    exec { 'solr-install-logging-jars':
      path      => ['/usr/bin', '/usr/sbin', '/bin'],
      cwd       => "/opt/solr",
      command   => "cp -v /opt/solr/solr-${solr::version}/example/lib/ext/*.jar /opt/solr/solr-${solr::version}/dist/solrj-lib/*.jar /opt/solr/solr-${solr::version}/example/resources/log4j.properties ${solr::tomcat_base}/webapps/solr/WEB-INF/lib",
      onlyif    => "test ! -f ${solr::tomcat_base}/webapps/solr/WEB-INF/lib/log4j-1.2.17.jar",
      require   => Exec['solr-extract'],
    }
  }

  tomcat::war { 'solr.war':
    catalina_base => $tomcat_base,
    war_source => "/opt/solr/solr-${solr::version}/dist/solr-${solr::version}.war",
    require => Class["solr::files"],
    notify => Service[$tomcat_version],
  }

}

Checkout the alternative manifests:

kenorb
  • 5,943
  • 1
  • 44
  • 53