我有Gentoo服务器,我在那里安装了node_exporter。我无法在机器上创建systemd服务,因为systemctl不存在。现在我必须为node_exporter创建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}"
esacNode_exporter.sh
#!/bin/sh
/opt/node_exporter/node_exporter --no-collector.diskstats但是这并不能完全启动这个过程,它只停留在Starting service上。我在这里有遗漏什么吗
发布于 2019-11-07 15:16:08
您可以尝试使用以下命令启动node_exporter:
su - $RUNAS -c "$SCRIPT >> $LOGFILE 2>&1 &"
echo $! > $PIDFILEhttps://stackoverflow.com/questions/58750894
复制相似问题