diff --git a/README.md b/README.md index 3ce99eb..efdbee2 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ * bin/check-cmd.rb * bin/check-process-restart.rb * bin/check-process.rb + * bin/check-process.sh + * bin/metrics-process-status ## Usage diff --git a/Rakefile b/Rakefile index 45be419..5ce0c83 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,9 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' -require 'rubocop/rake_task' +require 'yard' require 'github/markup' +require 'rubocop/rake_task' require 'redcarpet' -require 'yard' require 'yard/rake/yardoc_task' desc 'Don\'t run Rubocop for unsupported versions' @@ -29,7 +29,7 @@ end desc 'Make all plugins executable' task :make_bin_executable do - `chmod -R +x bin/*` + `chmod -R +x bin/***/*.rb` end task default: args diff --git a/bin/check-process.sh b/bin/check-process.sh new file mode 100644 index 0000000..a047765 --- /dev/null +++ b/bin/check-process.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# Check process +# +# === +# +# Examples: +# +# # check by process name +# check-process.sh -p nginx +# +# # check by PID file +# check-process.sh -f /var/spool/postfix/pid/master.pid +# +# Date: 2014-09-12 +# Author: Jun Ichikawa +# +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. + +# get arguments +while getopts 'p:f:h' OPT; do + case $OPT in + p) PROCESS=$OPTARG;; + f) PID_FILE=$OPTARG;; + h) hlp="yes";; + *) unknown="yes";; + esac +done + +# usage +HELP=" + usage: $0 [ -p value -f value -h ] + + -p --> process name + -f --> file path to pid file + -h --> print this help screen +" + +if [ "$hlp" = "yes" ]; then + echo "$HELP" + exit 0 +fi + +if [ ${PROCESS} ]; then + scriptname=`basename $0` + ret=`ps aux | grep "${PROCESS}" | grep -v grep | grep -v $scriptname` + if [ ! "${ret}" ]; then + echo "CRITICAL - process ${PROCESS} does not exist" + exit 2 + fi + echo "PROCESS OK - ${PROCESS}" + exit 0 +fi + +if [ ${PID_FILE} ]; then + if [ ! -e ${PID_FILE} ]; then + echo "CRITICAL - PID file ${PID_FILE} does not exist" + exit 2 + fi + pid=`cat ${PID_FILE} | tr -d ' '` + if [ ! -f /proc/${pid}/status ]; then + echo "CRITICAL - status of ${PID_FILE} not found" + exit 2 + fi + echo "PROCESS OK - ${PID_FILE}" + exit 0 +fi + +echo "$HELP" +exit 2 diff --git a/bin/process-status-metrics.rb b/bin/metrics-process-status.rb similarity index 100% rename from bin/process-status-metrics.rb rename to bin/metrics-process-status.rb