Skip to content

Instantly share code, notes, and snippets.

@JoergM
Created June 13, 2015 07:44
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save JoergM/489b21d903134db5d3c2 to your computer and use it in GitHub Desktop.
Save JoergM/489b21d903134db5d3c2 to your computer and use it in GitHub Desktop.
Prometheus init file for RHEL 5 or 6
#!/bin/bash
#
# /etc/rc.d/init.d/prometheus
#
# Prometheus monitoring server
#
# chkconfig: 2345 20 80 Read
# description: Prometheus monitoring server
# processname: prometheus
# Source function library.
. /etc/rc.d/init.d/functions
PROGNAME=prometheus
PROG=/usr/bin/local/$PROGNAME
USER=prometheus
LOGFILE=/var/log/prometheus/prometheus.log
DATADIR=/var/data/prometheus
LOCKFILE=/var/run/$PROGNAME.pid
CONFIG_FILE=/etc/prometheus/prometheus.yml
ALERT_MGR_URL=localhost:9093
start() {
echo -n "Starting $PROGNAME: "
daemon --user $USER --pidfile="$LOCKFILE" "$PROG -config.file $CONFIG_FILE -storage.local.path $DATADIR -alertmanager.url $ALERT_MGR_URL &>$LOGFILE &"
echo $(pidofproc $PROGNAME) >$LOCKFILE
echo
}
stop() {
echo -n "Shutting down $PROGNAME: "
killproc $PROGNAME
rm -f $LOCKFILE
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $PROGNAME
;;
restart)
stop
start
;;
reload)
echo "Sending SIGHUP to $PROGNAME"
kill -SIGHUP $(pidofproc $PROGNAME)
;;
*)
echo "Usage: <servicename> {start|stop|status|reload|restart}"
exit 1
;;
esac
@somnmos
Copy link

somnmos commented Aug 16, 2018

hi, man. i get a error like the follow with your init file.

Error parsing commandline arguments: unknown short flag '-c'
prometheus: error: unknown short flag '-c'

@clipperjoe
Copy link

In case anyone comes across this in the future, the: unknown short flag '-c' is actually an issue with how switches are handled in Prometheus 2.0.

The new argument is --config.file $CONFIG_FILE

Also these arguments have to be removed: -storage.local.path $DATADIR -alertmanager.url $ALERT_MGR_URL &>$LOGFILE

As Storage and Alertmanager are handled differently in Prometheus 2.0 or greater.

Documented information here: https://prometheus.io/docs/prometheus/2.0/migration/

@nitin194
Copy link

Thanks for publishing. It helped me run prometheus in old EC2 Linux AMI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment