diff --git a/libraries/provider_service.rb b/libraries/provider_service.rb index f0cc5f2f1..439bf2365 100644 --- a/libraries/provider_service.rb +++ b/libraries/provider_service.rb @@ -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) diff --git a/templates/default/systemd-env.erb b/templates/default/systemd-env.erb new file mode 100644 index 000000000..ef80a27f1 --- /dev/null +++ b/templates/default/systemd-env.erb @@ -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 %> +