Skip to content

Instantly share code, notes, and snippets.

@nicdoye
Created June 27, 2014 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicdoye/0730daed15a396034bd0 to your computer and use it in GitHub Desktop.
Save nicdoye/0730daed15a396034bd0 to your computer and use it in GitHub Desktop.
Simple shell script for monit to check if a lock file (containing a pid) has been left hanging around for a process that is not a daemon.
#!/bin/bash
. /lib/lsb/init-functions
pidofproc "$@" &>> /dev/null
retval=$?
# Ignore cases such as retval=3 (Pid file doesn't exist)
if [ $retval -ne 1 ]
then
retval=0
fi
exit $retval
# Can be used with monit configuration:
# check program testone with path "/etc/monit.d/libexec/pidfile-checker.sh -p /tmp/testone.pid /tmp/server.sh"
# if status != 0 then exec "/bin/rm -f /tmp/testone.pid"
#
# You can add "as uid <username> group <groupname>" to the end of the exec statement if you like (I do).
# You probably want to set a sensible alert message.
#
# Note that 'with path "command args"' was only supported in some version of monit > 5.5.1 and <= 5.8.1
# before that mysterious release, you could only use commands without arguments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment