Prometheus init script for CentOS 6
Create init file.
1 2 3 |
touch /etc/rc.d/init.d/prometheus chmod 755 /etc/rc.d/init.d/prometheus vi /etc/rc.d/init.d/prometheus |
Add following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#!/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/hostonnet/prometheus/$PROGNAME USER=prometheus LOGFILE=/var/log/prometheus.log DATADIR=/usr/hostonnet/prometheus/data LOCKFILE=/var/run/$PROGNAME.pid CONFIG_FILE=/usr/hostonnet/prometheus/prometheus.yml ALERT_MGR_URL=localhost:9093 start() { echo -n "Starting $PROGNAME: " cd /usr/hostonnet/prometheus/ #daemon --user $USER --pidfile="$LOCKFILE" "$PROG -config.file $CONFIG_FILE -storage.local.path $DATADIR -alertmanager.url $ALERT_MGR_URL &>$LOGFILE &" daemon --user $USER --pidfile="$LOCKFILE" "$PROG -config.file $CONFIG_FILE -storage.local.path $DATADIR &>$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: service prometheus {start|stop|status|reload|restart}" exit 1 ;; esac |
Create User For Prometheus
1 2 3 4 |
groupadd -r prometheus useradd -r -g prometheus -s /sbin/nologin -d /usr/hostonnet/prometheus/ -c "prometheus Daemons" prometheus chown -R prometheus:prometheus /usr/hostonnet/prometheus/ chown prometheus:prometheus /var/log/prometheus.log |
Run prometheus on Boot
1 2 |
chkconfig --add prometheus chkconfig prometheus on |
Verify it is enabled
1 2 3 |
[root@backup ~]# chkconfig --list | grep prome prometheus 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@backup ~]# |
“3:on” will start prometheus on run level 3, that is normal boot.
Start Prometheus
1 2 3 |
[root@backup ~]# service prometheus start Starting prometheus: [ OK ] [root@backup ~]# |