Last active
August 24, 2018 08:41
-
-
Save kenzo0107/eebb6c1c06ba04b7073c171580cec445 to your computer and use it in GitHub Desktop.
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 | |
# /etc/init.d/node_exporter | |
# config: /etc/prometheus/node_exporter.conf | |
# pidfile: /var/run/prometheus/node_exporter.pid | |
# | |
# preparation: | |
# - mkdir -p /var/run/prometheus | |
# - mkdir -p /var/log/prometheus | |
# - git clone git clone http://github.com/bmc/daemonize.git | |
# | |
# Source function library. | |
. /etc/init.d/functions | |
RETVAL=0 | |
DAEMON_USER="root" | |
PROG="node_exporter" | |
DAEMON=/bin/${PROG} | |
PID_FILE=/var/run/prometheus/${PROG}.pid | |
LOCK_FILE=/var/lock/subsys/${PROG} | |
LOG_FILE=/var/log/prometheus/${PROG}.log | |
start() { | |
if check_status > /dev/null; then | |
echo "node_exporter is already running" | |
exit 0 | |
fi | |
echo -n $"Starting node_exporter: " | |
daemonize -u ${DAEMON_USER} -p ${PID_FILE} -l ${LOCK_FILE} -a -e ${LOG_FILE} -o ${LOG_FILE} ${DAEMON} ${ARGS} | |
RETVAL=$? | |
echo "" | |
return $RETVAL | |
} | |
stop() { | |
echo -n $"Stopping node_exporter: " | |
killproc -p ${PID_FILE} -d 10 ${DAEMON} | |
RETVAL=$? | |
echo | |
[ $RETVAL = 0 ] && rm -f ${LOCK_FILE} ${PID_FILE} | |
return $RETVAL | |
} | |
check_status() { | |
status -p ${PID_FILE} ${DAEMON} | |
RETVAL=$? | |
return $RETVAL | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
check_status | |
;; | |
reload|force-reload) | |
reload | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
N=/etc/init.d/${NAME} | |
echo "Usage: $N {start|stop|status|restart|force-reload}" >&2 | |
RETVAL=2 | |
;; | |
esac | |
exit ${RETVAL} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment