Skip to content

Instantly share code, notes, and snippets.

@adamjakab
Created November 24, 2014 12:08
Show Gist options
  • Save adamjakab/ea2e49bee698923006df to your computer and use it in GitHub Desktop.
Save adamjakab/ea2e49bee698923006df to your computer and use it in GitHub Desktop.
Centos cpumon service (chkconfig compatible)
#!/bin/bash
#
# Author: Adam Jakab
#
# chkconfig: - 90 12
# description: CPU monitoring service with custom script
# processname: cpumon.sh
# pidfile: /var/run/cpumon.pid
#
scriptname="cpumon.sh"
scriptpath="/data_mount_1/cpumon"
exec="${scriptpath}/${scriptname}"
pidfile="/var/run/cpumon.pid"
# Get function from functions library
. /etc/rc.d/init.d/functions
# Start the service
start() {
[ -x ${exec} ] || exit 5
action $"Starting CPUMON service: " /bin/true
${exec} >/dev/null 2>&1 &
pid=$!
echo ${pid} > ${pidfile}
return 0
}
# Stop the service
stop() {
action $"Stopping CPUMON service: " /bin/true
pid=$(cat "${pidfile}")
if [ -n "${pid}" ]; then
/bin/kill "${pid}" >/dev/null 2>&1
ret=$?
else
ret=99
fi
### Now, delete the lock file ###
rm -f "${pidfile}"
return ${ret}
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status ${scriptname}
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment