Skip to content

Commit 503d625

Browse files
committed
Add Amazon Linux init script
Add support for 'amazon' platform for init script template. Fixes sous-chefs#387.
1 parent 57dac3e commit 503d625

File tree

1 file changed

+188
-0
lines changed

1 file changed

+188
-0
lines changed

templates/amazon/initscript.erb

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#!/bin/sh
2+
#
3+
# elasticsearch <summary>
4+
#
5+
# chkconfig: 2345 80 20
6+
# description: Starts and stops a single elasticsearch instance on this system
7+
#
8+
9+
### BEGIN INIT INFO
10+
# Provides: Elasticsearch
11+
# Required-Start: $network $named
12+
# Required-Stop: $network $named
13+
# Default-Start: 2 3 4 5
14+
# Default-Stop: 0 1 6
15+
# Short-Description: This service manages the elasticsearch daemon
16+
# Description: Elasticsearch is a very scalable, schema-free and high-performance search solution supporting multi-tenancy and near realtime search.
17+
### END INIT INFO
18+
19+
#
20+
# init.d / servicectl compatibility (openSUSE)
21+
#
22+
if [ -f /etc/rc.status ]; then
23+
. /etc/rc.status
24+
rc_reset
25+
fi
26+
27+
#
28+
# Source function library.
29+
#
30+
if [ -f /etc/rc.d/init.d/functions ]; then
31+
. /etc/rc.d/init.d/functions
32+
fi
33+
34+
# Sets the default values for elasticsearch variables used in this script
35+
ES_USER="elasticsearch"
36+
ES_GROUP="elasticsearch"
37+
ES_HOME="/usr/share/elasticsearch"
38+
MAX_OPEN_FILES=65535
39+
MAX_MAP_COUNT=262144
40+
LOG_DIR="/var/log/elasticsearch"
41+
DATA_DIR="/var/lib/elasticsearch"
42+
CONF_DIR="/etc/elasticsearch"
43+
44+
PID_DIR="/var/run/elasticsearch"
45+
46+
# Source the default env file
47+
ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>"
48+
if [ -f "$ES_ENV_FILE" ]; then
49+
. "$ES_ENV_FILE"
50+
fi
51+
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+
58+
exec="$ES_HOME/bin/elasticsearch"
59+
prog="<%= @program_name %>"
60+
pidfile="$PID_DIR/${prog}.pid"
61+
62+
export ES_HEAP_SIZE
63+
export ES_HEAP_NEWSIZE
64+
export ES_DIRECT_SIZE
65+
export ES_JAVA_OPTS
66+
export ES_GC_LOG_FILE
67+
export JAVA_HOME
68+
69+
lockfile=/var/lock/subsys/$prog
70+
71+
# backwards compatibility for old config sysconfig files, pre 0.90.1
72+
if [ -n $USER ] && [ -z $ES_USER ] ; then
73+
ES_USER=$USER
74+
fi
75+
76+
checkJava() {
77+
if [ -x "$JAVA_HOME/bin/java" ]; then
78+
JAVA="$JAVA_HOME/bin/java"
79+
else
80+
JAVA=`which java`
81+
fi
82+
83+
if [ ! -x "$JAVA" ]; then
84+
echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
85+
exit 1
86+
fi
87+
}
88+
89+
start() {
90+
checkJava
91+
[ -x $exec ] || exit 5
92+
if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then
93+
echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set"
94+
return 7
95+
fi
96+
if [ -n "$MAX_OPEN_FILES" ]; then
97+
ulimit -n $MAX_OPEN_FILES
98+
fi
99+
if [ -n "$MAX_LOCKED_MEMORY" ]; then
100+
ulimit -l $MAX_LOCKED_MEMORY
101+
fi
102+
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
103+
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
104+
fi
105+
export ES_GC_LOG_FILE
106+
107+
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
108+
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
109+
mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR"
110+
fi
111+
if [ -n "$pidfile" ] && [ ! -e "$pidfile" ]; then
112+
touch "$pidfile" && chown "$ES_USER":"$ES_GROUP" "$pidfile"
113+
fi
114+
115+
cd $ES_HOME
116+
echo -n $"Starting $prog: "
117+
# if not running, start it up here, usually something like "daemon $exec"
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
119+
retval=$?
120+
echo
121+
[ $retval -eq 0 ] && touch $lockfile
122+
return $retval
123+
}
124+
125+
stop() {
126+
echo -n $"Stopping $prog: "
127+
# stop it here, often "killproc $prog"
128+
killproc -p $pidfile -d 86400 $prog
129+
retval=$?
130+
echo
131+
[ $retval -eq 0 ] && rm -f $lockfile
132+
return $retval
133+
}
134+
135+
restart() {
136+
stop
137+
start
138+
}
139+
140+
reload() {
141+
restart
142+
}
143+
144+
force_reload() {
145+
restart
146+
}
147+
148+
rh_status() {
149+
# run checks to determine if the service is running or use generic status
150+
status -p $pidfile $prog
151+
}
152+
153+
rh_status_q() {
154+
rh_status >/dev/null 2>&1
155+
}
156+
157+
158+
case "$1" in
159+
start)
160+
rh_status_q && exit 0
161+
$1
162+
;;
163+
stop)
164+
rh_status_q || exit 0
165+
$1
166+
;;
167+
restart)
168+
$1
169+
;;
170+
reload)
171+
rh_status_q || exit 7
172+
$1
173+
;;
174+
force-reload)
175+
force_reload
176+
;;
177+
status)
178+
rh_status
179+
;;
180+
condrestart|try-restart)
181+
rh_status_q || exit 0
182+
restart
183+
;;
184+
*)
185+
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
186+
exit 2
187+
esac
188+
exit $?

0 commit comments

Comments
 (0)