"Fossies" - the Fresh Open Source Software Archive

Member "graylog-3.3.3/bin/graylogctl" (29 Jul 2020, 3012 Bytes) of package /linux/misc/graylog-3.3.3.tgz:


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. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env bash
    2 
    3 CMD=$1
    4 NOHUP=${NOHUP:=$(which nohup)}
    5 PS=${PS:=$(which ps)}
    6 
    7 # default java
    8 JAVA_CMD=${JAVA_CMD:=$(which java)}
    9 
   10 get_pid() {
   11     cat "${GRAYLOG_PID}" 2> /dev/null
   12 }
   13 
   14 pid_running() {
   15     kill -0 $1 2> /dev/null
   16 }
   17 
   18 die() {
   19     echo $*
   20     exit 1
   21 }
   22 
   23 if [ -n "$JAVA_HOME" ]
   24 then
   25     # try to use $JAVA_HOME
   26     if [ -x "$JAVA_HOME"/bin/java ]
   27     then
   28         JAVA_CMD="$JAVA_HOME"/bin/java
   29     else
   30         die "$JAVA_HOME"/bin/java is not executable
   31     fi
   32 fi
   33 
   34 # resolve links - $0 may be a softlink
   35 GRAYLOGCTL="$0"
   36 
   37 while [ -h "$GRAYLOGCTL" ]; do
   38     ls=$(ls -ld "$GRAYLOGCTL")
   39     link=$(expr "$ls" : '.*-> \(.*\)$')
   40     if expr "$link" : '/.*' > /dev/null; then
   41         GRAYLOGCTL="$link"
   42     else
   43         GRAYLOGCTL=$(dirname "$GRAYLOGCTL")/"$link"
   44     fi
   45 done
   46 
   47 # take variables from environment if set
   48 GRAYLOGCTL_DIR=${GRAYLOGCTL_DIR:=$(dirname "$GRAYLOGCTL")}
   49 GRAYLOG_SERVER_JAR=${GRAYLOG_SERVER_JAR:=graylog.jar}
   50 GRAYLOG_CONF=${GRAYLOG_CONF:=/etc/graylog/server/server.conf}
   51 GRAYLOG_PID=${GRAYLOG_PID:=/tmp/graylog.pid}
   52 LOG_FILE=${LOG_FILE:=log/graylog-server.log}
   53 LOG4J=${LOG4J:=}
   54 DEFAULT_JAVA_OPTS="-Djava.library.path=${GRAYLOGCTL_DIR}/../lib/sigar -Xms1g -Xmx1g -XX:NewRatio=1 -server -XX:+ResizeTLAB -XX:+UseConcMarkSweepGC -XX:+CMSConcurrentMTEnabled -XX:+CMSClassUnloadingEnabled -XX:-OmitStackTraceInFastThrow"
   55 if $JAVA_CMD -XX:+PrintFlagsFinal 2>&1 |grep -q UseParNewGC; then
   56     DEFAULT_JAVA_OPTS="${DEFAULT_JAVA_OPTS} -XX:+UseParNewGC"
   57 fi
   58 JAVA_OPTS="${JAVA_OPTS:="$DEFAULT_JAVA_OPTS"}"
   59 
   60 start() {
   61     echo "Starting graylog-server ..."
   62     cd "$GRAYLOGCTL_DIR/.."
   63     "${NOHUP}" "${JAVA_CMD}" ${JAVA_OPTS} ${LOG4J} -jar "${GRAYLOG_SERVER_JAR}" server -f "${GRAYLOG_CONF}" -p "${GRAYLOG_PID}" >> "${LOG_FILE}" 2>> "${LOG_FILE}" &
   64 }
   65 
   66 run() {
   67     echo "Running graylog-server ..."
   68     cd "$GRAYLOGCTL_DIR/.."
   69     exec "${JAVA_CMD}" ${JAVA_OPTS} ${LOG4J} -jar "${GRAYLOG_SERVER_JAR}" server -f "${GRAYLOG_CONF}" -p "${GRAYLOG_PID}"
   70 }
   71 
   72 stop() {
   73     if [ ! -f "${GRAYLOG_PID}" ]; then
   74       die "Not stopping. PID file not found: ${GRAYLOG_PID}"
   75     fi
   76 
   77     PID=$(get_pid)
   78 
   79     echo "Stopping graylog-server ($PID) ..."
   80     echo "Waiting for graylog-server to halt."
   81 
   82     kill $PID
   83 
   84     while "$PS" -p $PID > /dev/null; do sleep 1; done;
   85     rm -f "${GRAYLOG_PID}"
   86 
   87     echo "graylog-server stopped"
   88 }
   89 
   90 restart() {
   91     echo "Restarting graylog-server ..."
   92     stop
   93     start
   94 }
   95 
   96 status() {
   97     PID=$(get_pid)
   98     if [ ! -z $PID ]; then
   99         if pid_running $PID; then
  100             echo "graylog-server running with PID ${PID}"
  101             return 0
  102         else
  103             rm "${GRAYLOG_PID}"
  104             die "Removed stale PID file ${GRAYLOG_PID} with ${PID}."
  105         fi
  106     fi
  107 
  108     die "graylog-server not running"
  109 }
  110 
  111 case "$CMD" in
  112     start)
  113         start
  114         ;;
  115     stop)
  116         stop
  117         ;;
  118     restart)
  119         restart
  120         ;;
  121     status)
  122         status
  123         ;;
  124     run)
  125         run
  126         ;;
  127     *)
  128         echo "Usage $0 {start|stop|restart|status|run}"
  129 esac