Skip to content

Commit

Permalink
Debian/Redhat package improvments
Browse files Browse the repository at this point in the history
This decision helps people who want to rollout the oracle java without having an openjdk java installed.

* Removed any hard dependency on Java in the debian package
* The debian init script does not check for an existing JAVA_HOME anymore
* Debian and RedHat initscripts now exit if they do not find a java binary (instead of starting elasticsearch in the background and swallowing the error as there is no way to log it in that case)
* Changed the debian init script to rely on the pid file instead of the argument name of process
* Added a useful error message in case no java binary is available (in elasticsearch shell script)

Closes #3304
Closes #3311
  • Loading branch information
spinscale committed Jul 15, 2013
1 parent 37edfe0 commit c59b0b2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
9 changes: 7 additions & 2 deletions bin/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ fi
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA=java
JAVA=$(which java)
fi

if [ ! -x "$JAVA" ]; then
echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
exit 1
fi

if [ -z "$ES_CLASSPATH" ]; then
Expand Down Expand Up @@ -169,7 +174,7 @@ while true; do
break
;;
*)
echo "Error parsing arguments!" >&2
echo "Error parsing argument $1!" >&2
exit 1
;;
esac
Expand Down
3 changes: 1 addition & 2 deletions src/deb/control/control
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Package: elasticsearch
Version: [[version]]
Architecture: all
Maintainer: Nicolas Huray <nicolas.huray@gmail.com>
Maintainer: Elasticsearch Team <info@elasticsearch.com>
Depends: libc6, adduser
Suggest: java7-runtime-headless | java6-runtime-headless | java7-runtime | java6-runtime
Section: web
Priority: optional
Homepage: http://www.elasticsearch.org/
Expand Down
46 changes: 26 additions & 20 deletions src/deb/init.d/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ JDK_DIRS="/usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-7-openjdk /usr/lib/jvm/ja
# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
Expand Down Expand Up @@ -112,24 +112,35 @@ export ES_JAVA_OPTS
# Check DAEMON exists
test -x $DAEMON || exit 0

case "$1" in
start)
if [ -z "$JAVA_HOME" ]; then
log_failure_msg "no JDK found - please set JAVA_HOME"
checkJava() {
set +e
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA=$(which java)
fi

if [ ! -x "$JAVA" ]; then
echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
exit 1
fi
set -e
}

case "$1" in
start)
checkJava

if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then
log_failure_msg "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set"
exit 1
fi

log_daemon_msg "Starting $DESC"

if start-stop-daemon --test --start --pidfile "$PID_FILE" \
--user "$ES_USER" --exec "$JAVA_HOME/bin/java" \
>/dev/null; then


set +e
start-stop-daemon --status --pidfile "$PID_FILE" >/dev/null
if [ "$?" != "0" ]; then
# Prepare environment
mkdir -p "$LOG_DIR" "$DATA_DIR" "$WORK_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR" "$WORK_DIR"
touch "$PID_FILE" && chown "$ES_USER":"$ES_GROUP" "$PID_FILE"
Expand All @@ -143,20 +154,18 @@ case "$1" in
fi

# Start Daemon
start-stop-daemon --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec /bin/bash -- -c "$DAEMON $DAEMON_OPTS"
start-stop-daemon --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS

sleep 1
if start-stop-daemon --test --start --pidfile "$PID_FILE" \
--user "$ES_USER" --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
start-stop-daemon --status --pidfile "$PID_FILE" >/dev/null
if [ "$?" != "0" ]; then
if [ -f "$PID_FILE" ]; then
rm -f "$PID_FILE"
fi
log_end_msg 1
else
log_end_msg 0
fi

else
log_progress_msg "(already running)"
log_end_msg 0
Expand Down Expand Up @@ -186,11 +195,8 @@ case "$1" in
;;
status)
set +e
start-stop-daemon --test --start --pidfile "$PID_FILE" \
--user "$ES_USER" --exec "$JAVA_HOME/bin/java" \
>/dev/null 2>&1
if [ "$?" = "0" ]; then

start-stop-daemon --status --pidfile "$PID_FILE" >/dev/null 2>&1
if [ "$?" != "0" ]; then
if [ -f "$PID_FILE" ]; then
log_success_msg "$DESC is not running, but pid file exists."
exit 1
Expand Down
16 changes: 16 additions & 0 deletions src/rpm/init.d/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,23 @@ if [ -n $USER ] && [ -z $ES_USER ] ; then
ES_USER=$USER
fi

checkJava() {
set +e
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA=$(which java)
fi

if [ ! -x "$JAVA" ]; then
echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
exit 1
fi
set -e
}

start() {
checkJava
[ -x $exec ] || exit 5
[ -f $CONF_FILE ] || exit 6
if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then
Expand Down

0 comments on commit c59b0b2

Please sign in to comment.