Skip to content

Commit a8fb481

Browse files
committed
Better init scripts for ES 2.0
- Pull latest init scripts for ES 2.0 - Ensure curl is installed, use a curl command to test at the end - Switch from CONF_FILE to CONF_DIR - Ensure [:enable, :start] on service resource when testing - Ensure /etc/sysconfig and /etc/default are used correctly
1 parent 0122233 commit a8fb481

File tree

15 files changed

+665
-134
lines changed

15 files changed

+665
-134
lines changed

.kitchen.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ platforms:
2323
- name: ubuntu-14.04
2424
run_list:
2525
- recipe[apt]
26+
- recipe[curl]
2627
- name: ubuntu-12.04
2728
run_list:
2829
- recipe[apt]
30+
- recipe[curl]
2931
- name: centos-6.7
3032
run_list:
3133
- recipe[yum]
34+
- recipe[curl]
3235
- recipe[elasticsearch_test::fix_nss] # see recipe header
3336

3437
suites:

Berksfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ group :integration do
77

88
# not a strict dependency, but necessary for TK testing
99
cookbook 'java'
10+
cookbook 'curl'
1011
end

libraries/provider_configure.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ElasticsearchCookbook::ConfigureProvider < Chef::Provider::LWRPBase
99
# lookup existing ES resources
1010
es_user = find_es_resource(run_context, :elasticsearch_user, new_resource)
1111
es_install = find_es_resource(run_context, :elasticsearch_install, new_resource)
12+
es_svc = find_es_resource(run_context, :elasticsearch_service, new_resource)
1213

1314
# if a subdir parameter is missing but dir is set, infer the subdir name
1415
# then go and be sure it's also set in the YML hash if it wasn't given there
@@ -33,7 +34,7 @@ class ElasticsearchCookbook::ConfigureProvider < Chef::Provider::LWRPBase
3334

3435
# Create ES directories
3536
#
36-
[new_resource.path_conf[es_install.type], new_resource.path_logs[es_install.type]].each do |path|
37+
[new_resource.path_conf[es_install.type], "#{new_resource.path_conf[es_install.type]}/scripts", new_resource.path_logs[es_install.type]].each do |path|
3738
d = directory path do
3839
owner es_user.username
3940
group es_user.groupname
@@ -68,14 +69,19 @@ class ElasticsearchCookbook::ConfigureProvider < Chef::Provider::LWRPBase
6869
# MAX_OPEN_FILES MAX_LOCKED_MEMORY MAX_MAP_COUNT
6970
params = {}
7071

71-
params[:JAVA_HOME] = new_resource.java_home
7272
params[:ES_HOME] = new_resource.path_home[es_install.type]
73-
params[:CONF_FILE] = "#{new_resource.path_conf[es_install.type]}/elasticsearch.yml"
73+
params[:CONF_DIR] = new_resource.path_conf[es_install.type]
74+
params[:DATA_DIR] = new_resource.path_data[es_install.type]
75+
params[:LOG_DIR] = new_resource.path_logs[es_install.type]
76+
params[:PID_DIR] = new_resource.path_pid[es_install.type]
77+
78+
params[:ES_USER] = es_user.username
79+
params[:ES_GROUP] = es_user.groupname
80+
81+
params[:JAVA_HOME] = new_resource.java_home
7482
params[:ES_HEAP_SIZE] = new_resource.allocated_memory
7583
params[:MAX_OPEN_FILES] = new_resource.nofile_limit
7684
params[:MAX_LOCKED_MEMORY] = new_resource.memlock_limit
77-
params[:ES_USER] = es_user.username
78-
params[:ES_GROUP] = es_user.groupname
7985

8086
params[:ES_JAVA_OPTS] = ""
8187
params[:ES_JAVA_OPTS] << "-server "
@@ -89,8 +95,10 @@ class ElasticsearchCookbook::ConfigureProvider < Chef::Provider::LWRPBase
8995
params[:ES_JAVA_OPTS] << "-Djna.nosys=true "
9096
params[:ES_JAVA_OPTS] << "#{new_resource.env_options} " if new_resource.env_options
9197

98+
default_config_name = es_svc.service_name || es_svc.instance_name || new_resource.instance_name || 'elasticsearch'
99+
92100
shell_template = template 'elasticsearch.in.sh' do
93-
path node['platform_family'] == 'rhel' ? '/etc/sysconfig/elasticsearch' : '/etc/default/elasticsearch'
101+
path node['platform_family'] == 'rhel' ? "/etc/sysconfig/#{default_config_name}" : "/etc/default/#{default_config_name}"
94102
source new_resource.template_elasticsearch_env
95103
cookbook new_resource.cookbook_elasticsearch_env
96104
mode 0755

libraries/provider_service.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class ElasticsearchCookbook::ServiceProvider < Chef::Provider::LWRPBase
1515
es_conf = find_es_resource(run_context, :elasticsearch_configure, new_resource)
1616

1717
d_r = directory es_conf.path_pid[es_install.type] do
18+
owner es_user.username
19+
group es_user.groupname
1820
mode '0755'
1921
recursive true
2022
action :nothing
@@ -31,6 +33,7 @@ class ElasticsearchCookbook::ServiceProvider < Chef::Provider::LWRPBase
3133
mode 0755
3234
variables(
3335
# we need to include something about #{progname} fixed in here.
36+
program_name: new_resource.service_name
3437
)
3538
action :nothing
3639
end

templates/centos/initscript.erb

100644100755
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,31 @@ MAX_OPEN_FILES=65535
3939
MAX_MAP_COUNT=262144
4040
LOG_DIR="/var/log/elasticsearch"
4141
DATA_DIR="/var/lib/elasticsearch"
42-
WORK_DIR="/tmp/elasticsearch"
4342
CONF_DIR="/etc/elasticsearch"
44-
CONF_FILE="/etc/elasticsearch/elasticsearch.yml"
43+
4544
PID_DIR="/var/run/elasticsearch"
4645

4746
# Source the default env file
48-
ES_ENV_FILE="/etc/sysconfig/elasticsearch"
47+
ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>"
4948
if [ -f "$ES_ENV_FILE" ]; then
5049
. "$ES_ENV_FILE"
5150
fi
5251

52+
# CONF_FILE setting was removed
53+
if [ ! -z "$CONF_FILE" ]; then
54+
echo "CONF_FILE setting is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed."
55+
exit 1
56+
fi
57+
5358
exec="$ES_HOME/bin/elasticsearch"
54-
prog="elasticsearch"
59+
prog="<%= @program_name %>"
5560
pidfile="$PID_DIR/${prog}.pid"
5661

5762
export ES_HEAP_SIZE
5863
export ES_HEAP_NEWSIZE
5964
export ES_DIRECT_SIZE
6065
export ES_JAVA_OPTS
66+
export ES_GC_LOG_FILE
6167
export JAVA_HOME
6268

6369
lockfile=/var/lock/subsys/$prog
@@ -83,7 +89,6 @@ checkJava() {
8389
start() {
8490
checkJava
8591
[ -x $exec ] || exit 5
86-
[ -f $CONF_FILE ] || exit 6
8792
if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then
8893
echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set"
8994
return 7
@@ -97,10 +102,7 @@ start() {
97102
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
98103
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
99104
fi
100-
if [ -n "$WORK_DIR" ]; then
101-
mkdir -p "$WORK_DIR"
102-
chown "$ES_USER":"$ES_GROUP" "$WORK_DIR"
103-
fi
105+
export ES_GC_LOG_FILE
104106

105107
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
106108
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
@@ -110,9 +112,10 @@ start() {
110112
touch "$pidfile" && chown "$ES_USER":"$ES_GROUP" "$pidfile"
111113
fi
112114

115+
cd $ES_HOME
113116
echo -n $"Starting $prog: "
114117
# if not running, start it up here, usually something like "daemon $exec"
115-
daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR
118+
daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR
116119
retval=$?
117120
echo
118121
[ $retval -eq 0 ] && touch $lockfile
@@ -122,7 +125,7 @@ start() {
122125
stop() {
123126
echo -n $"Stopping $prog: "
124127
# stop it here, often "killproc $prog"
125-
killproc -p $pidfile -d 20 $prog
128+
killproc -p $pidfile -d 86400 $prog
126129
retval=$?
127130
echo
128131
[ $retval -eq 0 ] && rm -f $lockfile

0 commit comments

Comments
 (0)