Created
November 24, 2014 12:08
-
-
Save adamjakab/ea2e49bee698923006df to your computer and use it in GitHub Desktop.
Centos cpumon service (chkconfig compatible)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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