Guest User

Untitled

a guest
Feb 8th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. set +e
  3.  
  4. pid="$(pgrep -f puppet-server-release.jar)"
  5.  
  6. restartfile="/opt/puppetlabs/server/data/puppetserver/restartcounter"
  7. start_timeout="${START_TIMEOUT:-300}"
  8.  
  9. realname="puppetserver"
  10. rundir="/var/run/puppetlabs/${realname}"
  11. PIDFILE="${rundir}/${realname}.pid"
  12.  
  13. if [ ! -e "${INSTALL_DIR}/ezbake-functions.sh" ]; then
  14. echo "Unable to find ${INSTALL_DIR}/ezbake-functions.sh script, failing start." 1>&2
  15. exit 1
  16. fi
  17.  
  18. /usr/bin/install --directory --owner=$USER --group=$GROUP --mode=755 "$rundir"
  19. if [ $? -ne 0 ]; then
  20. echo "Unable to create/set permissions for rundir: ${rundir}" 1>&2
  21. exit 1
  22. fi
  23.  
  24. . "${INSTALL_DIR}/ezbake-functions.sh"
  25.  
  26. write_pid_file() {
  27. echo "$pid" > "$PIDFILE"
  28. if [ $? -ne 0 ]; then
  29. echo "Unable to write pid file: ${PIDFILE}" 1>&2
  30. terminate_java_process
  31. exit 1
  32. fi
  33. }
  34.  
  35. terminate_java_process() {
  36. echo "Startup script was terminated before completion" 1>&2
  37. kill_pid "$pid" "$PIDFILE" "$SERVICE_STOP_RETRIES"
  38. exit 1
  39. }
  40.  
  41. if [ -n "$pid" ]; then
  42. write_pid_file
  43. exit 0
  44. fi
  45.  
  46. rm -f "$PIDFILE"
  47.  
  48. init_restart_file "$restartfile" || exit $?
  49.  
  50. ${JAVA_BIN} ${JAVA_ARGS} -Djava.security.egd=/dev/urandom \
  51. -XX:OnOutOfMemoryError="kill -9 %p" \
  52. -cp ${INSTALL_DIR}/puppet-server-release.jar \
  53. clojure.main \
  54. -m puppetlabs.trapperkeeper.main \
  55. --config "${CONFIG}" \
  56. --bootstrap-config "${BOOTSTRAP_CONFIG}" \
  57. --restart-file "${restartfile}" &
  58.  
  59. # $! is the process id of the last backgrounded process, the Java process above.
  60. pid=$!
  61. trap terminate_java_process SIGHUP SIGINT SIGTERM
  62. write_pid_file
  63.  
  64. cur="$(head -n 1 "$restartfile")"
  65. initial="$cur"
  66.  
  67. timeout="$start_timeout"
  68. while [ "$cur" == "$initial" ] ;do
  69. kill -0 $pid >/dev/null 2>&1
  70. if [ $? -ne 0 ]; then
  71. rm -f "$PIDFILE"
  72. echo "Background process $pid exited before start had completed" 1>&2
  73. exit 1
  74. fi
  75.  
  76. sleep 1
  77. cur="$(head -n 1 "$restartfile")"
  78.  
  79. ((timeout--))
  80. if [ $timeout -eq 0 ]; then
  81. echo "Startup timed out after $start_timeout seconds" 1>&2
  82. terminate_java_process
  83. rm -f "$PIDFILE"
  84. exit 1
  85. fi
  86. done
  87.  
  88. write_pid_file
  89. exit 0
Advertisement
Add Comment
Please, Sign In to add comment