From 2269df255c8627f819afd3d2d6bb99d809b2ac9c Mon Sep 17 00:00:00 2001 From: gentlejo Date: Thu, 4 Oct 2018 20:57:49 +0900 Subject: [PATCH] Add node_exporter script for init.d (#1059) * Add node_exporter script for init.d Signed-off-by: gentlejo --- examples/init.d/node_exporter | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 examples/init.d/node_exporter diff --git a/examples/init.d/node_exporter b/examples/init.d/node_exporter new file mode 100755 index 00000000..74c62432 --- /dev/null +++ b/examples/init.d/node_exporter @@ -0,0 +1,63 @@ +#!/bin/bash + +RETVAL=0 +PROG="node_exporter" +EXEC="/etc/node_exporter/node_exporter" +LOCKFILE="/var/lock/subsys/$PROG" +OPTIONS="-web.listen-address=:9201" + +# Source function library. +if [ -f /etc/rc.d/init.d/functions ]; then + . /etc/rc.d/init.d/functions +else + echo "/etc/rc.d/init.d/functions is not exists" + exit 0 +fi + +start() { + if [ -f $LOCKFILE ] + then + echo "$PROG is already running!" + else + echo -n "Starting $PROG: " + nohup $EXEC $OPTIONS >/dev/null 2>&1 & + RETVAL=$? + [ $RETVAL -eq 0 ] && touch $LOCKFILE && success || failure + echo + return $RETVAL + fi +} + +stop() { + echo -n "Stopping $PROG: " + killproc $EXEC + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -r $LOCKFILE && success || failure + echo +} + +restart () +{ + stop + sleep 1 + start +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status $PROG + ;; + restart) + restart + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 +esac +exit $RETVAL