Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly reference "environment file" in init scripts #98

Merged
merged 2 commits into from
Apr 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions libraries/env_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Cookbook Name:: kafka
# Libraries:: env_file
#

module Kafka
module EnvFile
def render_variable(key, value, export=false)
variable = sprintf('%s=%p', key, value.to_s)
export ? sprintf('export %s', variable) : variable
end

def export?
node.kafka.init_style.to_sym != :systemd
end
end
end
1 change: 0 additions & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def kafka_init_opts
'debian' => '/etc/default/kafka',
'default' => '/etc/sysconfig/kafka',
})
opts[:env_template] = 'systemd/kafka.env.erb'
opts[:source] = value_for_platform_family({
'default' => 'systemd/default.erb'
})
Expand Down
4 changes: 2 additions & 2 deletions recipes/_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
end

template kafka_init_opts[:env_path] do
source kafka_init_opts.fetch(:env_template, 'env.erb')
source 'env.erb'
owner 'root'
group 'root'
mode '644'
variables(main_class: 'kafka.Kafka')
helpers(Kafka::EnvFile)
if restart_on_configuration_change?
notifies :create, 'ruby_block[coordinate-kafka-start]', :immediately
end
Expand Down
23 changes: 11 additions & 12 deletions templates/default/env.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/sh
export SCALA_VERSION="<%= node.kafka.scala_version %>"
export JMX_PORT="<%= node.kafka.jmx_port %>"
<%= render_variable('SCALA_VERSION', node.kafka.scala_version, export?) %>
<%= render_variable('JMX_PORT', node.kafka.jmx_port, export?) %>

export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:<%= node.kafka.config_dir %>/log4j.properties"
export KAFKA_HEAP_OPTS="<%= node.kafka.heap_opts %>"
export KAFKA_GC_LOG_OPTS="<%= node.kafka.gc_log_opts %>"
export KAFKA_OPTS="<%= node.kafka.generic_opts %>"
export KAFKA_JVM_PERFORMANCE_OPTS="<%= node.kafka.jvm_performance_opts %>"
export KAFKA_JMX_OPTS="<%= node.kafka.jmx_opts %>"
<%= render_variable('KAFKA_LOG4J_OPTS', sprintf('-Dlog4j.configuration=file:%s', ::File.join(node.kafka.config_dir, 'log4j.properties')), export?) %>
<%= render_variable('KAFKA_HEAP_OPTS', node.kafka.heap_opts, export?) %>
<%= render_variable('KAFKA_GC_LOG_OPTS', node.kafka.gc_log_opts, export?) %>
<%= render_variable('KAFKA_OPTS', node.kafka.generic_opts, export?) %>
<%= render_variable('KAFKA_JVM_PERFORMANCE_OPTS', node.kafka.jvm_performance_opts, export?) %>
<%= render_variable('KAFKA_JMX_OPTS', node.kafka.jmx_opts, export?) %>

KAFKA_RUN="<%= node.kafka.install_dir %>/bin/kafka-run-class.sh"
KAFKA_ARGS="<%= @main_class %>"
KAFKA_CONFIG="<%= node.kafka.config_dir %>/server.properties"
<%= render_variable('KAFKA_RUN', ::File.join(node.kafka.install_dir, 'bin', 'kafka-run-class.sh')) %>
<%= render_variable('KAFKA_ARGS', 'kafka.Kafka') %>
<%= render_variable('KAFKA_CONFIG', ::File.join(node.kafka.config_dir, 'server.properties')) %>
13 changes: 0 additions & 13 deletions templates/default/systemd/kafka.env.erb

This file was deleted.

2 changes: 1 addition & 1 deletion templates/default/sysv/debian.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PIDFILE=/var/run/$NAME.pid
[ -f /lib/lsb/init-functions ] && . /lib/lsb/init-functions

# Load additional configuration
[ -f /etc/default/$NAME ] && . /etc/default/$NAME
[ -f <%= @env_path %> ] && . <%= @env_path %>

<%= render 'partials/check_running.erb', variables: {user: @user} -%>

Expand Down
2 changes: 1 addition & 1 deletion templates/default/sysv/default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RETVAL=0
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network

# Load additional configuration
[ -f /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
[ -f <%= @env_path %> ] && . <%= @env_path %>

# Check that networking is up
[ "$NETWORKING" = "no" ] && exit $RETVAL
Expand Down
2 changes: 1 addition & 1 deletion templates/default/upstart/default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ limit nofile <%= @ulimit %> <%= @ulimit %>
setuid <%= @user %>

script
[ -f /etc/default/<%= @daemon_name %> ] && . /etc/default/<%= @daemon_name %>
[ -f <%= @env_path %> ] && . <%= @env_path %>
exec $KAFKA_RUN $KAFKA_ARGS $KAFKA_CONFIG
end script

Expand Down