Prometheus 节点导出器的init.d脚本/服务

Prometheus 节点导出器的init.d脚本/服务,prometheus,prometheus-node-exporter,Prometheus,Prometheus Node Exporter,我有Gentoo服务器,在那里我安装了node_exporter。我无法在计算机上创建systemd服务,因为systemctl不存在。现在我必须为node_导出器创建init.d服务。 我已经用下面的脚本创建了服务 #!/bin/sh ### BEGIN INIT INFO # Provides: node_exporter # Required-Start: $local_fs $network $named $time $syslog # Required-Stop: $local_f

我有Gentoo服务器,在那里我安装了node_exporter。我无法在计算机上创建systemd服务,因为systemctl不存在。现在我必须为node_导出器创建init.d服务。 我已经用下面的脚本创建了服务



#!/bin/sh
### BEGIN INIT INFO
# Provides: node_exporter
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description:
### END INIT INFO

 SCRIPT=<path to node_exporter.sh>
 RUNAS=root

  PIDFILE=/var/run/node_exporter.pid
  LOGFILE=/var/log/node_exporter.log

   start() {
       if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then
           echo 'Service already running' >&2
           return 1
           fi
           echo 'Starting service' >&2
           local CMD="$SCRIPT &> \"$LOGFILE\" && echo \$! > $PIDFILE"
           su -c "$CMD" $RUNAS > "$LOGFILE"
           echo 'Service started' >&2
   }

    stop() {
        if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
            echo 'Service not running' >&2
            return 1
            fi
            echo 'Stopping service' >&2
            kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
            echo 'Service stopped' >&2
    }

     uninstall() {
         echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
         local SURE
         read SURE
         if [ "$SURE" = "yes" ]; then
             stop
             rm -f "$PIDFILE"
             echo "Notice: log file is not be removed: '$LOGFILE'" >&2
             update-rc.d -f  remove
             rm -fv "$0"
             fi
     }

      case "$1" in
      start)
      start
      ;;
      stop)
      stop
      ;;
      uninstall)
      uninstall
      ;;
      retart)
      stop
      start
      ;;
      *)
      echo "Usage: $0 {start|stop|restart|uninstall}"
      esac


但这并不能完全启动流程,它只能停留在
启动服务上。此处是否缺少任何内容

您可以尝试使用以下命令启动节点导出器:

su - $RUNAS -c "$SCRIPT >> $LOGFILE 2>&1 &"
echo $! > $PIDFILE
su - $RUNAS -c "$SCRIPT >> $LOGFILE 2>&1 &"
echo $! > $PIDFILE