RedHat CentOS6 SysV init and CentOS7 Systemd unit
CentOS6 SysV init sample
#!/bin/bash#chkconfig: 345 99 99#description:node_exporter service and add /etc/rc.d/init.d directory#processname:node_exporter#desc:chkconfig --add node_exporter;execute service node_exporter startcount="0"instance_path="/usr/local/bin/node_exporter"instance_path_arg="--web.disable-exporter-metrics"case $1 instart) ${instance_path} ${instance_path_arg} &>/dev/null & ;;stop) pkill -f ${instance_path} ;;status) count=$(ps -ef | grep "${instance_path} ${instance_path_arg}" | grep -v "grep" | wc -l) if [ $count -gt 0 ];then echo "[node_exporter] is running..." else echo "[node_exporter] is not running..." fi ;;esac
CentOS7 Systemd unit sample
# /usr/lib/systemd/system/mysqld_exporter.service# add mysqld_exporter.service to /usr/lib/systemd/system# execute systemctl daemon-reload# execute systemctl status|restart|start mysqld_exporter[Unit]Description=Mysqld ExporterWants=network-online.targetAfter=network-online.target[Service]User=rootGroup=rootType=simpleEnvironment=DATA_SOURCE_NAME=hadoop-mysqld-exporter:hadoop-mysqld-exporter@(172.16.0.60:3306)/ExecStart=/usr/local/bin/mysqld_exporter --web.disable-exporter-metrics --web.config=/path to othersRestart=on-failureRestartForceExitStatus=16RestartPreventExitStatus=1StandardOutput=syslogStandardError=syslog[Install]WantedBy=multi-user.target