Guest User

Untitled

a guest
May 31st, 2012
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #!/bin/sh
  3. ### BEGIN INIT INFO
  4. # Provides: puppet-dashboard-workers
  5. # Required-Start: $local_fs $remote_fs $network $syslog
  6. # Required-Stop: $local_fs $remote_fs $network $syslog
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # X-Interactive: true
  10. # Short-Description: Start/stop puppet-dashboard-workers delayed_job helpers
  11. ### END INIT INFO
  12. #
  13. # puppet-dashboard-workers This init.d script is used to start puppet-dashboard-workers.
  14.  
  15. name=puppet-dashboard-workers
  16. ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
  17.  
  18. set -e
  19.  
  20. . /lib/lsb/init-functions
  21.  
  22. test -f /etc/default/rcS && . /etc/default/rcS
  23. test -f /etc/default/${name} && . /etc/default/${name}
  24.  
  25. # Set defaults in case they're not in the above defaults file:
  26. DASHBOARD_HOME=${DASHBOARD_HOME:-/var/www/localhost/htdocs/puppet-dashboard}
  27. DASHBOARD_USER=${DASHBOARD_USER:-apache}
  28. DASHBOARD_RUBY=${DASHBOARD_RUBY:-/usr/bin/ruby}
  29. DASHBOARD_ENVIRONMENT=${DASHBOARD_ENVIRONMENT:-production}
  30. DASHBOARD_IFACE=${DASHBOARD_IFACE:-0.0.0.0}
  31. DASHBOARD_PORT=${DASHBOARD_PORT:-80}
  32.  
  33. check_dashboard_enabled_option() {
  34. if [ ! "$START" = "yes" ]; then
  35. log_warning_msg "Not starting Puppet Dashboard Workers, disabled via /etc/default/${name}"
  36. return 1
  37. else
  38. return 0
  39. fi
  40. }
  41.  
  42. check_puppet_dashboard_worker_status() {
  43. RETVAL=1
  44. for pidfile in $(ls -1 "${DASHBOARD_HOME}"/tmp/pids/delayed_job*.pid 2>/dev/null)
  45. do
  46. status_of_proc -p $pidfile ${DASHBOARD_RUBY} "Puppet Dashboard Worker (pid $(cat $pidfile))" || return $?
  47. RETVAL=$?
  48. done
  49. if [ "$RETVAL" -eq "1" ] ; then
  50. log_daemon_msg "${name} is not running."
  51. fi
  52. return $RETVAL
  53. }
  54.  
  55.  
  56.  
  57. stop_puppet_dashboard_workers() {
  58. RETVAL=0
  59. for pidfile in $(ls -1 "${DASHBOARD_HOME}"/tmp/pids/delayed_job*.pid 2>/dev/null)
  60. do
  61. start-stop-daemon --stop --quiet --oknodo --pidfile $pidfile --retry 10
  62. ((RETVAL=RETVAL+$?))
  63. done
  64. return $RETVAL
  65. }
  66.  
  67. start_puppet_dashboard_workers() {
  68. start-stop-daemon --start --quiet --oknodo --user ${DASHBOARD_USER} --chuid ${DASHBOARD_USER} --exec /bin/bash -- -e -c "
  69. export PATH='${PATH}';
  70. export RUBYLIB='${RUBYLIB:-}';
  71. export RAILS_ENV=production;
  72. ${DASHBOARD_HOME}/script/delayed_job -p dashboard -n ${NUM_DELAYED_JOB_WORKERS:-2} -m start;"
  73. check_puppet_dashboard_worker_status
  74. }
  75.  
  76.  
  77. case $1 in
  78. start)
  79. log_daemon_msg "Starting Puppet Dashboard Workers"
  80. if ! check_dashboard_enabled_option; then
  81. log_end_msg 0
  82. exit
  83. fi
  84. if start_puppet_dashboard_workers; then
  85. log_end_msg 0
  86. else
  87. log_end_msg 1
  88. fi
  89. ;;
  90. stop)
  91. log_daemon_msg "Stopping Puppet Dashboard Workers"
  92. if stop_puppet_dashboard_workers ; then
  93. log_end_msg 0
  94. else
  95. log_end_msg 1
  96. fi
  97. ;;
  98. restart)
  99. log_daemon_msg "Restarting Puppet Dashboard Workers"
  100. set +e
  101. stop_puppet_dashboard_workers
  102. RET="$?"
  103. set -e
  104. case ${RET} in
  105. 0)
  106. # Old server stopped
  107. if ! check_dashboard_enabled_option; then
  108. log_end_msg 0
  109. exit
  110. fi
  111. if start_puppet_dashboard_workers; then
  112. log_end_msg 0
  113. else
  114. log_end_msg 1
  115. fi
  116. ;;
  117. 1)
  118. # Server not running
  119. log_progress_msg "(not running)"
  120. log_end_msg 0
  121. ;;
  122. *)
  123. # Failed to stop
  124. log_progress_msg "(failed to stop)"
  125. log_end_msg 1
  126. ;;
  127. esac
  128. ;;
  129. status)
  130. check_puppet_dashboard_worker_status && exit 0 || exit $?
  131. ;;
  132. *)
  133. log_action_msg "Usage: /etc/init.d/${name} {start|stop|restart|status}"
  134. exit 1
  135. ;;
  136. esac
  137.  
  138. exit 0
RAW Paste Data