mbok / logsniffer

logsniffer is a sophisticated open source web tool for parsing, viewing, monitoring and analyzing log data - smarter, collaborative and easier. [No longer maintaned]
GNU Lesser General Public License v3.0
104 stars 47 forks source link

init script #88

Closed jimdoesvoip closed 7 years ago

jimdoesvoip commented 7 years ago

Has anyone written a init script (Centos/RHEL 6 style) for logsniffer?

jimdoesvoip commented 7 years ago

I assume that perhaps no one reading the issues has done this or done it recently.

We did end up writing a functional init script for this. We've setup and tested on CentOS6, so assume it will work on other distros, but pre-systemd distros. Thanks Jamie for the help in finishing and fixing what I started.

Here is what we've used. Note that this supports adding to chkconfig which is always nice.

cat /etc/init.d/logsniffer

!/bin/bash

chkconfig: 2345 95 05

description: logserver daemon

BEGIN INIT INFO

Provides: logsniffer

Required-Start: $java

Required-Stop: $java

Short-Description: Start and stop logsniffer service.

Description: -

Date-Creation: -

Date-Last-Modification: -

Author: -

END INIT INFO

Variables

PGREP=/usr/bin/pgrep PKILL=/usr/bin/pkill JAVA=/usr/bin/java

Start the logsniffer

start() { echo "Starting logsniffer..."

Verify if the service is running

$PGREP -f logsniffer.war > /dev/null
VERIFIER=$?
if [ $VERIFIER == 0 ]
then
    echo "The service is already running"
else
    #Run the jar file logsniffer service
    $JAVA -jar /root/logsniffer.war > /dev/null 2>&1 &
    #sleep time before the service verification
    #sleep 10
    #Verify if the service is running
    $PGREP -f logsniffer.war  > /dev/null
    VERIFIER=$?
    if [ $VERIFIER == 0 ]
    then
        echo "Service was successfully started"
    else
        echo "Failed to start service"
    fi
fi
echo

}

Stop the logsniffer

stop() { echo "Stopping logsniffer..."

Verify if the service is running

$PKILL -f logsniffer.war
VERIFIER=$?
if [ $VERIFIER == 0 ]
then
    echo "Service stopped"
elif [ $VERIFIER == 1 ]
then
    echo "Service already stopped"
else
    echo "pkill error: $VERIFIER"
fi

}

Verify the status of logsniffer

status() { echo "Checking status of logsniffer..."

Verify if the service is running

$PGREP -f logsniffer.war
VERIFIER=$?
if [ $VERIFIER == 0 ]
then
    echo "Service is running"
else
    echo "Service is stopped"
fi
echo

}

Main logic

case "$1" in start) start ;; stop) stop ;; status) status ;; restart|reload) stop start ;; *) echo $"Usage: $0 {start|stop|status|restart|reload}" exit 1 esac exit 0 #