bash - Running logstash forwarder as a daemon service -


i found article explain how make start stop service ; http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

and wrote :

#!/bin/bash # # chkconfig: 3 80 20 # description: boop-logstash-forwarder # # function functions library . /etc/init.d/functions # start service  logstash_forwarder="/logiciels/logstash-forwarder/logstash-forwarder" lf_conf="/appli/projects/boop-logstash-forwarder/logstash-forwarder.conf" service_name="boop-logstash-forwarder"  start() {         initlog -c "echo -n starting $service_name: "         $logstash_forwarder -config=$lf_conf &         ### create lock file ###         touch /var/lock/subsys/$service_name         success $"$service_name startup"         echo } # restart service stop() {         initlog -c "echo -n stopping $service_name: "         killproc $service_name         ### now, delete lock file ###         rm -f /var/lock/subsys/$service_name         echo } ### main logic ### case "$1" in   start)         start         ;;   stop)         stop         ;;   status)         status $service_name         ;;   restart|reload|condrestart)         stop         start         ;;   *)         echo $"usage: $0 {start|stop|restart|reload|status}"         exit 1 esac exit 0 

i have 2 problem this, first logstash forwarder taking control of console verbose, should in launch command redirect it's output file?

second , biggest problem stop command won't work, :

stopping looping-logstash-forwarder:                       [failed] 

did wront in script?

thanks.

ps : red hat enterprise linux server release 5.9

here working vesion uses kill instead of killproc :

#!/bin/bash # # chkconfig: 3 80 20 # description: boop-logstash-forwarder # # function functions library . /etc/init.d/functions # start service  logstash_forwarder="/logiciels/logstash-forwarder/logstash-forwarder" lf_conf="/appli/projects/boop-logstash-forwarder/logstash-forwarder.conf" logfile="/appli/projects/boop-logstash-forwarder/logstash-forwarder.log" pidfile="/appli/projects/boop-logstash-forwarder/logstash-forwarder.pid" service_name="boop-logstash-forwarder"  blockuntilfileexist () {     while ! [[ -f "$1" ]] ;         echo "waiting creation of $1"         sleep 1     done }  start() {         initlog -c "echo -n starting $service_name: "         $logstash_forwarder -config=$lf_conf > $logfile 2>&1 & echo $! > $pidfile         blockuntilfileexist $pidfile         success $"$service_name startup"         echo }  stop() {         initlog -c "echo -n stopping $service_name: "         if [ ! -f $pidfile ];             echo "process pid contained in $pidfile not exist"             exit         else             echo "killing process pid contained in $pidfile"             kill `cat $pidfile`         fi         echo } ### main logic ### case "$1" in   start)         start         ;;   stop)         stop         ;;   status)         status $service_name         ;;   restart|reload|condrestart)1         stop         start         ;;   *)         echo $"usage: $0 {start|stop|restart|reload|status}"         exit 1 esac exit 0 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -