Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set +e
- pid="$(pgrep -f puppet-server-release.jar)"
- restartfile="/opt/puppetlabs/server/data/puppetserver/restartcounter"
- start_timeout="${START_TIMEOUT:-300}"
- realname="puppetserver"
- rundir="/var/run/puppetlabs/${realname}"
- PIDFILE="${rundir}/${realname}.pid"
- if [ ! -e "${INSTALL_DIR}/ezbake-functions.sh" ]; then
- echo "Unable to find ${INSTALL_DIR}/ezbake-functions.sh script, failing start." 1>&2
- exit 1
- fi
- /usr/bin/install --directory --owner=$USER --group=$GROUP --mode=755 "$rundir"
- if [ $? -ne 0 ]; then
- echo "Unable to create/set permissions for rundir: ${rundir}" 1>&2
- exit 1
- fi
- . "${INSTALL_DIR}/ezbake-functions.sh"
- write_pid_file() {
- echo "$pid" > "$PIDFILE"
- if [ $? -ne 0 ]; then
- echo "Unable to write pid file: ${PIDFILE}" 1>&2
- terminate_java_process
- exit 1
- fi
- }
- terminate_java_process() {
- echo "Startup script was terminated before completion" 1>&2
- kill_pid "$pid" "$PIDFILE" "$SERVICE_STOP_RETRIES"
- exit 1
- }
- if [ -n "$pid" ]; then
- write_pid_file
- exit 0
- fi
- rm -f "$PIDFILE"
- init_restart_file "$restartfile" || exit $?
- ${JAVA_BIN} ${JAVA_ARGS} -Djava.security.egd=/dev/urandom \
- -XX:OnOutOfMemoryError="kill -9 %p" \
- -cp ${INSTALL_DIR}/puppet-server-release.jar \
- clojure.main \
- -m puppetlabs.trapperkeeper.main \
- --config "${CONFIG}" \
- --bootstrap-config "${BOOTSTRAP_CONFIG}" \
- --restart-file "${restartfile}" &
- # $! is the process id of the last backgrounded process, the Java process above.
- pid=$!
- trap terminate_java_process SIGHUP SIGINT SIGTERM
- write_pid_file
- cur="$(head -n 1 "$restartfile")"
- initial="$cur"
- timeout="$start_timeout"
- while [ "$cur" == "$initial" ] ;do
- kill -0 $pid >/dev/null 2>&1
- if [ $? -ne 0 ]; then
- rm -f "$PIDFILE"
- echo "Background process $pid exited before start had completed" 1>&2
- exit 1
- fi
- sleep 1
- cur="$(head -n 1 "$restartfile")"
- ((timeout--))
- if [ $timeout -eq 0 ]; then
- echo "Startup timed out after $start_timeout seconds" 1>&2
- terminate_java_process
- rm -f "$PIDFILE"
- exit 1
- fi
- done
- write_pid_file
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment