diff options
| author | Lasse Luttermann Poulsen <llp@nordu.net> | 2017-08-17 10:52:51 +0200 |
|---|---|---|
| committer | Lasse Luttermann Poulsen <llp@nordu.net> | 2017-08-17 10:52:51 +0200 |
| commit | 7c2948c0fd1f5831e2669acadb0cba48f02e7c5c (patch) | |
| tree | 0abc7cb937c3395191232da656a47eaca933be66 /node-exporter/node-exporter_init.d | |
Added prometheus node_exporter, work in progress.
Diffstat (limited to 'node-exporter/node-exporter_init.d')
| -rw-r--r-- | node-exporter/node-exporter_init.d | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/node-exporter/node-exporter_init.d b/node-exporter/node-exporter_init.d new file mode 100644 index 0000000..04a56f9 --- /dev/null +++ b/node-exporter/node-exporter_init.d @@ -0,0 +1,100 @@ +#!/bin/bash +# +# +# +# Start on runlevels 3, 4 and 5. Start late, kill early. +# chkconfig: 345 95 05 +# +# +#!/bin/bash + +# absolute path to executable binary +progpath='/usr/sbin/node_exporter' + +# arguments to script +opts='' + +# binary program name +prog=$(basename $progpath) + +# pid file +pidfile="/var/run/${prog}.pid" + +# make sure full path to executable binary is found +! [ -x $progpath ] && echo "$progpath: executable not found" && exit 1 + +eval_cmd() { + local rc=$1 + if [ $rc -eq 0 ]; then + echo '[ OK ]' + else + echo '[FAILED]' + fi + return $rc +} + +start() { + # see if running + local pids=$(pgrep $prog) + + if [ -n "$pids" ]; then + echo "$prog (pid $pids) is already running" + return 0 + fi + printf "%-50s%s" "Starting $prog: " '' + $progpath $opts & + + # save pid to file if you want + echo $! > $pidfile + + # check again if running + pgrep $prog >/dev/null 2>&1 + eval_cmd $? +} + +stop() { + # see if running + local pids=$(pgrep $prog) + + if [ -z "$pids" ]; then + echo "$prog not running" + return 0 + fi + printf "%-50s%s" "Stopping $prog: " '' + rm -f $pidfile + kill -9 $pids + eval_cmd $? +} + +status() { + # see if running + local pids=$(pgrep $prog) + + if [ -n "$pids" ]; then + echo "$prog (pid $pids) is running" + else + echo "$prog is stopped" + fi +} + +case $1 in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + restart) + stop + sleep 1 + start + ;; + *) + echo "Usage: $0 {start|stop|status|restart}" + exit 1 +esac + +exit $?
\ No newline at end of file |
