Skip to content

Instantly share code, notes, and snippets.

@safoorsafdar
Last active March 6, 2020 15:00
Show Gist options
  • Save safoorsafdar/626ba7b60885aec74cb7cb5baf07189d to your computer and use it in GitHub Desktop.
Save safoorsafdar/626ba7b60885aec74cb7cb5baf07189d to your computer and use it in GitHub Desktop.
Amazon Linux or CentOS 6 or RHEL 6 Service for Prometheus Node Exporter
#!/bin/sh
#
# example start stop daemon for CentOS (sysvinit)
#
# chkconfig: - 64 36
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 2 3 4 6
# Required-Start:
# description: node_exporter start stop daemon for CentOS
# processname: node_exporter
# pidfile: none
# lockfile: /var/lock/subsys/example
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
bin_dir="${BIN_DIR:-/usr/local/bin}"
APPNAME="node_exporter"
APPBIN="${bin_dir}/node_exporter"
APPARGS="-collectors.enabled conntrack,diskstats,entropy,edac,filefd,filesystem,hwmon,infiniband,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat,wifi,zfs"
LOGFILE="/var/log/$APPNAME/error.log"
LOCKFILE="/var/lock/subsys/$APPNAME"
USER=root
LOGPATH=$(dirname $LOGFILE)
start() {
[ -x $APPBIN ] || exit 5
[ -d $LOGPATH ] || mkdir $LOGPATH
[ -f $LOGFILE ] || touch $LOGFILE
echo -n $"Starting $APPNAME: "
daemon --user $USER --check $APPNAME nohup $APPBIN >> $LOGFILE 2>&1 &
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
echo -n $"Stopping $APPNAME: "
killproc $APPBIN
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
return $RETVAL
}
restart() {
stop
start
}
rh_status() {
echo -n "in: rh_status"
status $APPNAME
}
rh_status_q() {
echo -n "in: rh_status_q"
rh_status >/dev/null 2>&1
}
reload(){
restart
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment