Skip to content

Instantly share code, notes, and snippets.

@solarmicrobe
Last active September 19, 2018 15:11
Show Gist options
  • Save solarmicrobe/3dadba8c9e5a746a8a5ea9f8660400c8 to your computer and use it in GitHub Desktop.
Save solarmicrobe/3dadba8c9e5a746a8a5ea9f8660400c8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Promethus SuSE system startup script
# Copyright (C) 2017 Russell Parks, Bats Global Markets, Inc.
# /etc/init.d/prometheus
#
# LSB compatible service control script; see http://www.linuxbase.org/spec/
#
### BEGIN INIT INFO
# Provides: prometheus
# Required-Start: $network $remote_fs
# Should-Start: $time
# Required-Stop: $remote_fs
# Should-Stop: $network
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: monitoring system and time series database.
# Description: Prometheus is a systems and service monitoring system.
# It collects metrics from configured targets at given intervals,
# evaluates rule expressions, displays the results,
# and can trigger alerts if some condition is observed to be true.
#
# chkconfig: 2345 80 80
# config: /etc/prometheus/prometheus.yml
# pidfile: /var/run/prometheus/prometheus.pid
#
#
### END INIT INFO
#set -e
# Source function library.
. /etc/rc.status
rc_reset
NAME=prometheus
DESC="Prometheus monitoring system"
PDIR=/opt/prometheus
DAEMON=$PDIR/prometheus
USER=prometheus
CONFIG=/etc/prometheus/prometheus.yml
PID="/var/run/prometheus/$NAME.pid"
LOG="/var/log/prometheus/$NAME.log"
GOSU=/usr/local/bin/gosu
RETVAL=0
ALERTMANAGER_OPTS="-alertmanager.url=http://localhost:9093/"
DAEMON_OPTS="$ALERTMANAGER_OPTS"
DAEMON_OPTS="$DAEMON_OPTS -config.file=$CONFIG -storage.local.path=/var/lib/prometheus"
DAEMON_OPTS="$DAEMON_OPTS -web.console.templates=$PDIR/consoles -web.console.libraries=$PDIR/console_libraries"
# Check if DAEMON binary exist
[ -f $DAEMON ] || exit 0
[ -f "/etc/sysconfig/$NAME" ] && . /etc/sysconfig/$NAME
service_checks() {
# Prepare directories
mkdir -p "/var/run/prometheus" "/var/log/prometheus"
chown -R $USER "/var/run/prometheus" "/var/log/prometheus"
# Check if PID exists
if [ -f "$PID" ]; then
PID_NUMBER=`cat $PID`
if [ -z "`ps axf | grep ${PID_NUMBER} | grep -v grep`" ]; then
echo "Service was aborted abnormally; clean the PID file and continue..."
rm -f "$PID"
else
echo "Service already started; skip..."
exit 1
fi
fi
}
start() {
service_checks $1
$GOSU $USER $DAEMON $DAEMON_OPTS > $LOG 2>&1 &
RETVAL=$?
echo $! > $PID
}
stop() {
killproc -p $PID $DAEMON
RETVAL=$?
}
reload() {
killproc -p $PID -HUP $DAEMON
RETVAL=$?
}
case "$1" in
start)
echo -n $"Starting $DESC -" "$NAME" $'\n'
start
;;
stop)
echo -n $"Stopping $DESC -" "$NAME" $'\n'
stop
;;
reload)
echo -n $"Reloading $DESC configuration -" "$NAME" $'\n'
reload
;;
restart|force-reload)
echo -n $"Restarting $DESC -" "$NAME" $'\n'
stop
start
;;
syntax)
$DAEMON --help
;;
status)
checkproc -p $PID $DAEMON
rc_status -v
;;
*)
echo -n $"Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|syntax|status}" $'\n'
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment