将logstash转发器作为守护程序服务运行

时间:2016-09-22 13:49:13

标签: bash redhat daemon

我发现这篇文章解释了如何开始停止服务; http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

所以我写了这个:

...
<script type="text/javascript">
   myVar = @(ViewBag.myVar);  // etc.
</script>
...

我有2个问题,首先是logstash转发器控制控制台是非常详细的,我应该在启动命令中将它的输出重定向到文件吗?

第二个也是最大的问题,停止命令不起作用,我得到:

var myVar = null;

function myFunc() {
   // Check for initialization
   if (myVar == null)
      alert("myVar not initialized!");
   ...
   // use myVar
   ...
}

我在剧本中做了什么吗?

感谢。

ps:红帽企业Linux服务器版本5.9

1 个答案:

答案 0 :(得分:1)

这是一个使用kill而不是killproc的工作人员:

#!/bin/bash
#
# chkconfig: 3 80 20
# description: boop-logstash-forwarder
#
# Get function from functions library
. /etc/init.d/functions
# Start the 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" ]] ; do
        echo "Waiting for 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 ]; then
            echo "process with pid contained in $PIDFILE does not exist"
            exit
        else
            echo "killing process with 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