Skip to content

Commit

Permalink
Add systemd support
Browse files Browse the repository at this point in the history
  • Loading branch information
hrak committed Jun 21, 2016
1 parent 306129a commit f5c4500
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
32 changes: 32 additions & 0 deletions libraries/provider_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ def whyrun_supported?
init_r.run_action(:create)
new_resource.updated_by_last_action(true) if init_r.updated_by_last_action?

# Create systemd unit file
#
if ::File.open('/proc/1/comm').gets.chomp == 'systemd'
directory "/etc/systemd/system/#{new_resource.service_name}.service.d" do
owner 'root'
group 'root'
mode 0755
action :nothing
end.run_action(:create)

systemd_r = template "/etc/systemd/system/#{new_resource.service_name}.service.d/env.conf" do
source 'systemd-env.erb'
owner 'root'
mode 0644
variables(
ES_USER: es_user.username,
ES_GROUP: es_user.groupname,
ES_HOME: es_conf.path_home[es_install.type],
CONF_DIR: es_conf.path_conf[es_install.type],
DATA_DIR: es_conf.path_data[es_install.type],
LOG_DIR: es_conf.path_logs[es_install.type],
PID_DIR: es_conf.path_pid[es_install.type],
MAX_OPEN_FILES: es_conf.nofile_limit,
# Systemd expects 'infinity' instead of 'unlimited'
MAX_LOCKED_MEMORY: es_conf.memlock_limit == 'unlimited' ? 'infinity' : es_conf.memlock_limit
)
action :nothing
end
systemd_r.run_action(:create)
new_resource.updated_by_last_action(true) if systemd_r.updated_by_last_action?
end

# flatten in an array here, in case the service_actions are a symbol vs. array
[new_resource.service_actions].flatten.each do |act|
passthrough_action(act)
Expand Down
21 changes: 21 additions & 0 deletions templates/default/systemd-env.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Service]
Environment=ES_HOME=<%= @ES_HOME %>
Environment=CONF_DIR=<%= @CONF_DIR %>
Environment=DATA_DIR=<%= @DATA_DIR %>
Environment=LOG_DIR=<%= @LOG_DIR %>
Environment=PID_DIR=<%= @PID_DIR %>
EnvironmentFile=-/etc/default/elasticsearch

WorkingDirectory=<%= @ES_HOME %>

User=<%= @ES_USER %>
Group=<%= @ES_GROUP %>

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=<%= @MAX_OPEN_FILES %>

# Specifies the maximum number of bytes of memory that may be locked into RAM
# Set to "infinity" if you use the 'bootstrap.mlockall: true' option
# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/default/elasticsearch
LimitMEMLOCK=<%= @MAX_LOCKED_MEMORY %>

0 comments on commit f5c4500

Please sign in to comment.