Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Jones committed Feb 17, 2015
1 parent bea3a0c commit 38a1005
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
71 changes: 71 additions & 0 deletions bin/check-process.sh
Original file line number Diff line number Diff line change
@@ -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 <jun1ka0@gmail.com>
#
# 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
File renamed without changes.

0 comments on commit 38a1005

Please sign in to comment.