"Fossies" - the Fresh Open Source Software Archive

Member "monasca-api-3.1.0/devstack/files/grafana/grafana-server" (27 Sep 2019, 3551 Bytes) of package /linux/misc/openstack/monasca-api-3.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /usr/bin/env bash
    2 
    3 # chkconfig: 2345 80 05
    4 # description: Grafana web server & backend
    5 # processname: grafana-server
    6 # config: /etc/grafana/grafana.ini
    7 # pidfile: /var/run/grafana-server.pid
    8 
    9 ### BEGIN INIT INFO
   10 # Provides:          grafana-server
   11 # Required-Start:    $all
   12 # Required-Stop:     $remote_fs $syslog
   13 # Default-Start:     2 3 4 5
   14 # Default-Stop:      0 1 6
   15 # Short-Description: Start grafana at boot time
   16 ### END INIT INFO
   17 
   18 #  tested on
   19 #  1. New lsb that define start-stop-daemon
   20 #  3. Centos with initscripts package installed
   21 
   22 PATH=/bin:/usr/bin:/sbin:/usr/sbin
   23 NAME=grafana-server
   24 DESC="Grafana Server"
   25 DEFAULT=/etc/default/$NAME
   26 
   27 GRAFANA_USER=grafana
   28 GRAFANA_GROUP=grafana
   29 GRAFANA_HOME=/usr/share/grafana
   30 CONF_DIR=/etc/grafana
   31 WORK_DIR=$GRAFANA_HOME
   32 DATA_DIR=/var/lib/grafana
   33 LOG_DIR=/var/log/grafana
   34 CONF_FILE=$CONF_DIR/grafana.ini
   35 MAX_OPEN_FILES=10000
   36 PID_FILE=/var/run/$NAME.pid
   37 DAEMON=/usr/sbin/$NAME
   38 
   39 umask 0027
   40 
   41 if [ `id -u` -ne 0 ]; then
   42     echo "You need root privileges to run this script"
   43     exit 4
   44 fi
   45 
   46 if [ ! -x $DAEMON ]; then
   47   echo "Program not installed or not executable"
   48   exit 5
   49 fi
   50 
   51 . /lib/lsb/init-functions
   52 
   53 if [ -r /etc/default/rcS ]; then
   54     . /etc/default/rcS
   55 fi
   56 
   57 # overwrite settings from default file
   58 if [ -f "$DEFAULT" ]; then
   59     . "$DEFAULT"
   60 fi
   61 
   62 DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR}"
   63 
   64 case "$1" in
   65   start)
   66 
   67     log_daemon_msg "Starting $DESC"
   68 
   69     pid=`pidofproc -p $PID_FILE grafana`
   70     if [ -n "$pid" ] ; then
   71         log_begin_msg "Already running."
   72         log_end_msg 0
   73         exit 0
   74     fi
   75 
   76     # Prepare environment
   77     mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$LOG_DIR" "$DATA_DIR"
   78     touch "$PID_FILE" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$PID_FILE"
   79 
   80   if [ -n "$MAX_OPEN_FILES" ]; then
   81         ulimit -n $MAX_OPEN_FILES
   82     fi
   83 
   84     # Start Daemon
   85     start-stop-daemon --start -b --chdir "$WORK_DIR" --user "$GRAFANA_USER" -c "$GRAFANA_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
   86     return=$?
   87     if [ $return -eq 0 ]
   88     then
   89       sleep 1
   90 
   91     # check if pid file has been written two
   92       if ! [[ -s $PID_FILE ]]; then
   93         log_end_msg 1
   94         exit 1
   95       fi
   96 
   97         i=0
   98         timeout=10
   99         # Wait for the process to be properly started before exiting
  100         until { cat "$PID_FILE" | xargs kill -0; } >/dev/null 2>&1
  101         do
  102             sleep 1
  103             i=$(($i + 1))
  104       if [ $i -gt $timeout ]; then
  105               log_end_msg 1
  106               exit 1
  107             fi
  108         done
  109   fi
  110   log_end_msg $return
  111     ;;
  112   stop)
  113     log_daemon_msg "Stopping $DESC"
  114 
  115     if [ -f "$PID_FILE" ]; then
  116         start-stop-daemon --stop --pidfile "$PID_FILE" \
  117             --user "$GRAFANA_USER" \
  118             --retry=TERM/20/KILL/5 >/dev/null
  119         if [ $? -eq 1 ]; then
  120             log_progress_msg "$DESC is not running but pid file exists, cleaning up"
  121         elif [ $? -eq 3 ]; then
  122             PID="`cat $PID_FILE`"
  123             log_failure_msg "Failed to stop $DESC (pid $PID)"
  124             exit 1
  125         fi
  126         rm -f "$PID_FILE"
  127     else
  128         log_progress_msg "(not running)"
  129     fi
  130     log_end_msg 0
  131     ;;
  132   status)
  133     status_of_proc -p $PID_FILE grafana grafana && exit 0 || exit $?
  134     ;;
  135   restart|force-reload)
  136     if [ -f "$PID_FILE" ]; then
  137         $0 stop
  138         sleep 1
  139     fi
  140     $0 start
  141     ;;
  142   *)
  143     log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}"
  144     exit 3
  145     ;;
  146 esac