diff --git a/files/etc/init.d/elasticsearch.FreeBSD.erb b/files/etc/init.d/elasticsearch.FreeBSD.erb
new file mode 100644
index 000000000..6fa853c80
--- /dev/null
+++ b/files/etc/init.d/elasticsearch.FreeBSD.erb
@@ -0,0 +1,149 @@
+#!/bin/sh
+#
+# This file is managed via PUPPET
+#
+# PROVIDE: elasticsearch
+# REQUIRE: NETWORKING SERVERS
+# BEFORE: DAEMON
+# KEYWORD: shutdown
+#
+# Add the following line to /etc/rc.conf to enable elasticsearch:
+#
+# elasticsearch_enable="YES"
+#
+# elasticsearch_user (username): Set to elasticsearch by default.
+# Set it to required username.
+# elasticsearch_group (group): Set to elasticsearch by default.
+# Set it to required group.
+# elasticsearch_config (path): Set to /usr/local/etc/elasticsearch/elasticsearch.yml by default.
+# Set it to the config file location.
+# elasticsearch_min_mem (num): Minumum JVM heap size, 256m by default.
+# elasticsearch_max_mem (num): Maximum JVM heap size, 1g by default.
+# elasticsearch_props (args): Additional java properties or arguments.
+# elasticsearch_tmp (path): Set to /var/tmp/elasticsearch by default.
+# Set it to the path to be used for temp files.
+#
+. /etc/rc.subr
+
+name=elasticsearch
+rcvar=elasticsearch_enable
+
+load_rc_config ${name}
+
+: ${elasticsearch_enable:="NO"}
+: ${elasticsearch_user:=elasticsearch}
+: ${elasticsearch_group:=elasticsearch}
+: ${elasticsearch_config:="/usr/local/etc/elasticsearch/<%= @resource[:instance] %>/elasticsearch.yml"}
+: ${elasticsearch_min_mem:="256m"}
+: ${elasticsearch_max_mem:="1g"}
+: ${elasticsearch_props:=""}
+: ${elasticsearch_tmp:="/var/tmp/elasticsearch"}
+
+# Force the JVM to use IPv4 stack
+# elasticshearch_props"-Djava.net.preferIPv4Stack=true"
+
+required_files="${elasticsearch_config}"
+pidfile="/var/run/${name}.pid"
+
+ES_LIB="/usr/local/lib/elasticsearch"
+ES_CLASSPATH=$ES_LIB/elasticsearch-1.7.5.jar:$ES_LIB/*:$ES_LIB/sigar/*
+
+java_options=" -server \
+ -Xms${elasticsearch_min_mem} \
+ -Xmx${elasticsearch_max_mem} \
+ -Xss256k \
+ -Djava.awt.headless=true \
+ -XX:+UseParNewGC \
+ -XX:+UseConcMarkSweepGC \
+ -XX:CMSInitiatingOccupancyFraction=75 \
+ -XX:+UseCMSInitiatingOccupancyOnly \
+ -XX:+HeapDumpOnOutOfMemoryError \
+ -XX:+DisableExplicitGC \
+ -Delasticsearch \
+ -Des.config=${elasticsearch_config} \
+ -cp ${ES_CLASSPATH}"
+
+extra_commands="console status"
+console_cmd="elasticsearch_console"
+start_precmd="elasticsearch_precmd"
+status_cmd="elasticsearch_status"
+stop_cmd="elasticsearch_stop"
+command="/usr/sbin/daemon"
+command_args="-f /usr/local/bin/java -Des.pidfile=${pidfile} ${elasticsearch_props} ${java_options} org.elasticsearch.bootstrap.Elasticsearch"
+
+elasticsearch_precmd()
+{
+ rc_pid=$(elasticsearch_check_pidfile $pidfile)
+
+ if [ -n "$rc_pid" ]; then
+ [ -n "$rc_fast" ] && return 0
+ echo "${name} is already running: $rc_pid"
+ return 1
+ fi
+ touch ${pidfile}
+ chown ${elasticsearch_user}:${elasticsearch_group} ${pidfile}
+ /usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 750 ${elasticsearch_tmp}
+ /usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 750 /var/db/elasticsearch
+ /usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 750 /var/log/elasticsearch
+}
+
+elasticsearch_console()
+{
+ rc_pid=$(elasticsearch_check_pidfile $pidfile)
+
+ if [ -n "$rc_pid" ]; then
+ [ -n "$rc_fast" ] && return 0
+ echo "${name} is already running: $rc_pid"
+ return 1
+ fi
+ /usr/local/bin/java -Des.foreground=yes ${elasticsearch_props} ${java_options} org.elasticsearch.bootstrap.Elasticsearch
+}
+
+
+elasticsearch_stop()
+{
+ rc_pid=$(elasticsearch_check_pidfile $pidfile)
+
+ if [ -z "$rc_pid" ]; then
+ [ -n "$rc_fast" ] && return 0
+ echo "${name} not running? (check $pidfile)."
+ return 1
+ fi
+
+ echo "Stopping ${name}."
+ kill ${rc_pid} 2> /dev/null
+}
+
+elasticsearch_status()
+{
+ rc_pid=$(elasticsearch_check_pidfile $pidfile)
+
+ if [ -z "$rc_pid" ]; then
+ [ -n "$rc_fast" ] && return 0
+ echo "${name} not running? (check $pidfile)."
+ return 1
+ fi
+ echo "${name} is running as pid ${rc_pid}."
+}
+
+elasticsearch_check_pidfile()
+{
+ _pidfile=$1
+ if [ -z "$_pidfile" ]; then
+ err 3 'USAGE: elasticsearch_check_pidfile pidfile'
+ fi
+ if [ ! -f $_pidfile ]; then
+ debug "pid file ($_pidfile): not readable."
+ return
+ fi
+ read _pid _junk < $_pidfile
+ if [ -z "$_pid" ]; then
+ debug "pid file ($_pidfile): no pid in file."
+ return
+ fi
+ if [ -n "`/usr/bin/su -m ${elasticsearch_user} -c '/usr/local/bin/jps -l' | grep -e "^$_pid"`" ]; then
+ echo -n $_pid
+ fi
+}
+
+run_rc_command "$1"
diff --git a/manifests/params.pp b/manifests/params.pp
index 2924c2471..a3ab06b34 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -84,6 +84,10 @@
$elasticsearch_user = '_elasticsearch'
$elasticsearch_group = '_elasticsearch'
}
+ 'FreeBSD': {
+ $elasticsearch_user = 'elasticsearch'
+ $elasticsearch_group = 'elasticsearch'
+ }
default: {
fail("\"${module_name}\" provides no user/group default value
for \"${::kernel}\"")
@@ -102,6 +106,9 @@
'OpenBSD': {
$download_tool = 'ftp -o'
}
+ 'FreeBSD': {
+ $download_tool = 'fetch -o'
+ }
default: {
fail("\"${module_name}\" provides no download tool default value
for \"${::kernel}\"")
@@ -128,6 +135,15 @@
$plugindir = "${homedir}/plugins"
$datadir = '/var/elasticsearch/data'
}
+ 'FreeBSD': {
+ $configdir = '/usr/local/etc/elasticsearch'
+ $logdir = '/var/log/elasticsearch'
+ $package_dir = '/var/cache/elasticsearch'
+ $installpath = undef
+ $homedir = '/usr/local/lib/elasticsearch'
+ $plugindir = "${homedir}/plugins"
+ $datadir = '/var/db/elasticsearch'
+ }
default: {
fail("\"${module_name}\" provides no config directory default value
for \"${::kernel}\"")
@@ -137,7 +153,7 @@
# packages
case $::operatingsystem {
'RedHat', 'CentOS', 'Fedora', 'Scientific', 'Amazon', 'OracleLinux', 'SLC',
- 'Debian', 'Ubuntu', 'OpenSuSE', 'SLES', 'OpenBSD': {
+ 'Debian', 'Ubuntu', 'OpenSuSE', 'SLES', 'OpenBSD', 'FreeBSD': {
$package = 'elasticsearch'
}
'Gentoo': {
@@ -284,6 +300,17 @@
$init_template = 'elasticsearch.OpenBSD.erb'
$pid_dir = '/var/run/elasticsearch'
}
+ 'FreeBSD': {
+ $service_name = 'elasticsearch'
+ $service_hasrestart = true
+ $service_hasstatus = true
+ $service_pattern = undef
+ $service_providers = 'freebsd'
+ $systemd_service_path = undef
+ $defaults_location = undef
+ $init_template = 'elasticsearch.FreeBSD.erb'
+ $pid_dir = '/var/run/elasticsearch'
+ }
default: {
fail("\"${module_name}\" provides no service parameters
for \"${::operatingsystem}\"")
diff --git a/manifests/service.pp b/manifests/service.pp
index f620208ac..c3fdf90e5 100644
--- a/manifests/service.pp
+++ b/manifests/service.pp
@@ -85,6 +85,14 @@
service_flags => $service_flags,
}
}
+ 'freebsd': {
+ elasticsearch::service::freebsd { $name:
+ ensure => $ensure,
+ status => $status,
+ init_template => $init_template,
+ service_flags => $service_flags,
+ }
+ }
'systemd': {
elasticsearch::service::systemd { $name:
ensure => $ensure,
diff --git a/manifests/service/freebsd.pp b/manifests/service/freebsd.pp
new file mode 100644
index 000000000..67412968f
--- /dev/null
+++ b/manifests/service/freebsd.pp
@@ -0,0 +1,162 @@
+# == Define: elasticsearch::service::freebsd
+#
+# This class exists to coordinate all service management related actions,
+# functionality and logical units in a central place.
+#
+# Note: "service" is the Puppet term and type for background processes
+# in general and is used in a platform-independent way. E.g. "service" means
+# "daemon" in relation to Unix-like systems.
+#
+#
+# === Parameters
+#
+# [*ensure*]
+# String. Controls if the managed resources shall be present or
+# absent. If set to absent:
+# * The managed software packages are being uninstalled.
+# * Any traces of the packages will be purged as good as possible. This may
+# include existing configuration files. The exact behavior is provider
+# dependent. Q.v.:
+# * Puppet type reference: {package, "purgeable"}[http://j.mp/xbxmNP]
+# * {Puppet's package provider source code}[http://j.mp/wtVCaL]
+# * System modifications (if any) will be reverted as good as possible
+# (e.g. removal of created users, services, changed log settings, ...).
+# * This is thus destructive and should be used with care.
+# Defaults to present.
+#
+# [*status*]
+# String to define the status of the service. Possible values:
+# * enabled: Service is running and will be started at boot time.
+# * disabled: Service is stopped and will not be started at boot
+# time.
+# * running: Service is running but will not be started at boot time.
+# You can use this to start a service on the first Puppet run instead of
+# the system startup.
+# * unmanaged: Service will not be started at boot time and Puppet
+# does not care whether the service is running or not. For example, this may
+# be useful if a cluster management software is used to decide when to start
+# the service plus assuring it is running on the desired node.
+# Defaults to enabled. The singular form ("service") is used for the
+# sake of convenience. Of course, the defined status affects all services if
+# more than one is managed (see service.pp to check if this is the
+# case).
+#
+# [*pid_dir*]
+# String, directory where to store the serice pid file
+#
+# [*init_template*]
+# Service file as a template
+#
+# [*service_flags*]
+# String, flags to pass to the service
+#
+# === Authors
+#
+# * Richard Pijnenburg
+#
+define elasticsearch::service::freebsd(
+ $ensure = $elasticsearch::ensure,
+ $status = $elasticsearch::status,
+ $pid_dir = $elasticsearch::pid_dir,
+ $init_template = $elasticsearch::init_template,
+ $service_flags = undef,
+) {
+
+ #### Service management
+
+ # set params: in operation
+ if $ensure == 'present' {
+
+ case $status {
+ # make sure service is currently running, start it on boot
+ 'enabled': {
+ $service_ensure = 'running'
+ $service_enable = true
+ }
+ # make sure service is currently stopped, do not start it on boot
+ 'disabled': {
+ $service_ensure = 'stopped'
+ $service_enable = false
+ }
+ # make sure service is currently running, do not start it on boot
+ 'running': {
+ $service_ensure = 'running'
+ $service_enable = false
+ }
+ # do not start service on boot, do not care whether currently running
+ # or not
+ 'unmanaged': {
+ $service_ensure = undef
+ $service_enable = false
+ }
+ # unknown status
+ # note: don't forget to update the parameter check in init.pp if you
+ # add a new or change an existing status.
+ default: {
+ fail("\"${status}\" is an unknown service status value")
+ }
+ }
+
+ # set params: removal
+ } else {
+
+ # make sure the service is stopped and disabled (the removal itself will be
+ # done by package.pp)
+ $service_ensure = 'stopped'
+ $service_enable = false
+
+ }
+
+ $notify_service = $elasticsearch::restart_config_change ? {
+ true => Service["elasticsearch-instance-${name}"],
+ false => undef,
+ }
+
+ if ( $status != 'unmanaged' and $ensure == 'present' ) {
+
+ # init file from template
+ if ($init_template != undef) {
+
+ elasticsearch_service_file { "/usr/local/etc/rc.d/elasticsearch_${name}":
+ ensure => $ensure,
+ content => file($init_template),
+ instance => $name,
+ notify => $notify_service,
+ package_name => $elasticsearch::package_name,
+ }
+ -> file { "/usr/local/etc/rc.d/elasticsearch_${name}":
+ ensure => $ensure,
+ owner => 'root',
+ group => '0',
+ mode => '0555',
+ before => Service["elasticsearch-instance-${name}"],
+ notify => $notify_service,
+ }
+
+ }
+
+ } elsif ($status != 'unmanaged') {
+
+ file { "/usr/local/etc/rc.d/elasticsearch_${name}":
+ ensure => 'absent',
+ subscribe => Service["elasticsearch-instance-${name}"],
+ }
+
+ }
+
+ if ( $status != 'unmanaged') {
+
+ # action
+ service { "elasticsearch-instance-${name}":
+ ensure => $service_ensure,
+ enable => $service_enable,
+ name => "elasticsearch_${name}",
+ flags => $service_flags,
+ hasstatus => $elasticsearch::params::service_hasstatus,
+ hasrestart => $elasticsearch::params::service_hasrestart,
+ pattern => $elasticsearch::params::service_pattern,
+ }
+
+ }
+
+}