Created
January 4, 2018 04:04
-
-
Save anri-c/81aa81ec3375db04b40f0a9efc4d0731 to your computer and use it in GitHub Desktop.
node_exporter init script
This file contains hidden or 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/sh | |
| ### BEGIN INFO | |
| # Providers: NodeExporter | |
| # Required-Start: $local_fs $network $named $time $syslog | |
| # Required-Stop: $local_fs $network $named $time $syslog | |
| # Default-Stert: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Description: Node exporter for prometheus | |
| ### END INIT INFO | |
| . /etc/init.d/functions | |
| DAEMON=/usr/sbin/node_exporter | |
| NAME=node_exporter | |
| USER=root | |
| PIDFILE=/var/run/prometheus/$NAME.pid | |
| LOGFILE=/var/log/prometheus/$NAME.log | |
| ARGS="" | |
| [ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME | |
| prepare() { | |
| mkdir -p `dirname $PIDFILE` || true | |
| mkdir -p `dirname $LOGFILE` || true | |
| chown -R $USER: /var/run/prometheus | |
| chown -R $USER: /var/log/prometheus | |
| } | |
| do_status() { | |
| if [ -f $PIDFILE ]; then | |
| PID=$(cat $PIDFILE) | |
| if [ -x "$(ps axf | grep ${PID} | grep -v grep)" ]; then | |
| echo "The process appears to be dead but pidfile still exists" | |
| else | |
| echo "Runnning, the PID is $PID" | |
| fi | |
| else | |
| echo "process not running" | |
| fi | |
| } | |
| do_start() { | |
| prepare | |
| echo -n "Starting daemon: "$NAME | |
| daemon --user $USER --pidfile $PIDFILE "nohup $DAEMON $ARGS >> $LOGFILE 2>&1 &" | |
| echo "." | |
| sleep 3 | |
| pidof $NAME > $PIDFILE | |
| } | |
| do_stop() { | |
| echo -n "Stopping daemon: "$NAME | |
| killproc -p $PIDFILE -d 30 $NAME | |
| echo "." | |
| } | |
| case "$1" in | |
| start) | |
| do_start | |
| ;; | |
| stop) | |
| do_stop | |
| ;; | |
| restart) | |
| do_stop | |
| do_start | |
| ;; | |
| status) | |
| do_status | |
| ;; | |
| *) | |
| echo "Usage: $1 {start|stop|restart|status}" | |
| exit 1 | |
| esac | |
| exit 0 |
This file contains hidden or 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
| # arguments to pass the node_exporter | |
| ARGS='--collector.diskstats.ignored-devices="^(ram|loop|fd)\\d+$"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment