Skip to content

Commit

Permalink
Support SysVinit (amzn1)
Browse files Browse the repository at this point in the history
  • Loading branch information
haruwo committed Aug 17, 2021
1 parent ba956ad commit 529a531
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ scrape_configs:
target_label: role
_EOD_


#
# Install to system
#

if hash systemctl; then
# systemd
cat > /usr/lib/systemd/system/prometheus.service <<'_EOD_'
[Unit]
Description=Prometheus
Expand All @@ -85,3 +92,91 @@ _EOD_
systemctl daemon-reload
systemctl enable prometheus.service
systemctl start prometheus.service

else # hash systemctl
# SysVinit
cat > /etc/init.d/prometheus-relay-agent <<'_EOD_'
#!/bin/bash
#
# /etc/rc.d/init.d/prometheus-relay-agent
#
# chkconfig: 2345 70 30
#
# pidfile: /var/run/prometheus-relay-agent.pid
# Source function library.
. /etc/init.d/functions
RETVAL=0
ARGS="--config.file=/opt/prometheus/prometheus.yml"
PROG="prometheus-relay-agent"
DAEMON="/opt/prometheus/prometheus"
PID_FILE=/var/run/${PROG}.pid
LOG_FILE=/var/log/node_exporter.log
LOCK_FILE=/var/lock/subsys/${PROG}
GOMAXPROCS=$(grep -c ^processor /proc/cpuinfo)
start() {
if check_status > /dev/null; then
echo "node_exporter is already running"
exit 0
fi
echo -n $"Starting node_exporter: "
${DAEMON} ${ARGS} 1>>${LOG_FILE} 2>&1 &
echo $! > ${PID_FILE}
RETVAL=$?
[ $RETVAL -eq 0 ] && touch ${LOCK_FILE}
echo ""
return $RETVAL
}
stop() {
if check_status > /dev/null; then
echo -n $"Stopping node_exporter: "
kill -9 "$(cat ${PID_FILE})"
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f ${LOCK_FILE} ${PID_FILE}
echo ""
return $RETVAL
else
echo "node_exporter is not running"
rm -f ${LOCK_FILE} ${PID_FILE}
return 0
fi
}
check_status() {
status -p ${PID_FILE} ${DAEMON}
RETVAL=$?
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
N=/etc/init.d/${NAME}
echo "Usage: $N {start|stop|restart}" >&2
RETVAL=2
;;
esac
exit ${RETVAL}
_EOD_

chmod +x /etc/init.d/prometheus-relay-agent
chkconfig --add prometheus-relay-agent
chkconfig prometheus-relay-agent on
service prometheus-relay-agent start

fi # hash systemctl

0 comments on commit 529a531

Please sign in to comment.