RedHat CentOS6 SysV init and CentOS7 Systemd unit

CentOS6 SysV init sample

#!/bin/bash

#chkconfig: 345 99 01
#Description:mysqld_exporter module
#processname:mysqld_exporter
#mv mysqld_exporter /etc/rc.d/init.d
#chkconfig --add mysqld_exporter
#service mysqld_exporter start | status | restart

count="0"
sqlexptPath="/usr/local/bin/mysqld_exporter"

case $1 in
  start) 
    ${sqlexptPath} --config.my-cnf=/root/.my.cnf >/dev/null 2>&1 &
    ;;
   
  stop) 
    pkill -f ${sqlexptPath}
    ;;

  status) 
    count=$(ps -ef | grep "${sqlexptPath}" | grep -v "grep" | wc -l)
    if [ $count -gt 0 ];then
      echo "[mysqld_exporter] is running..."
    else
      echo "[mysqld_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 Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
Environment='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 others
Restart=on-failure
RestartForceExitStatus=16
RestartPreventExitStatus=1
StandardOutput=syslog
StandardError=syslog

[Install]
WantedBy=multi-user.target