lumberjack 托运人初始化脚本

lumberjack 托运人初始化脚本

我正在使用 lumberjack shipper 来处理 logstash。我需要 init.d 脚本来在 centos 系统上启动 lumberjack。我有基于 debian 系统的脚本,但无法在 Centos 上运行。

我现在有这个脚本:

#!/bin/sh
#
#   /etc/init.d/lumberjack
#
#   Starts and stops Lumberjack as a "daemon".#
# chkconfig: 2345 30 70
# description: Starts and stops Lumberjack as a daemon.

# The name of this service
NAME=lumberjack

### Start Configuration Options ###

# The JSON config to use
LJ_CONFIG=/etc/logstash-forwarder/config

 # The Lumberjack binary wrapper
LJ_BIN=`/opt/logstash-forwarder/bin/logstash-forwarder`

# Any Lumberjack options
LJ_OPTS="-spool-size 1000"

# The log file for local info
LJ_LOG=/var/log/lumberjack/lumberjack

# The PID file
PID_FILE=/var/run/lumberjack

# The command to daemonize
DAEMON="nohup ${LJ_BIN} -config ${LJ_CONFIG} ${LJ_OPTS} >>${LJ_LOG} 2>&1 &"

### End Configuration Options ###

. /etc/logstash-forwarder/config

    check_prereqs() {
  if [ -z ${LJ_BIN} ]; then
    echo "ERROR: Unable to locate Lumberjack binary, make sure it's installed."
    exit 1
  elif [ ! -f ${LJ_CONFIG} ]; then
    echo "ERROR: LJ_CONFIG (${LJ_CONFIG}) doesn't exist."
    exit 1
  elif [ ! -d `dirname ${LJ_LOG}` ]; then
    echo "ERROR: LJ_LOG parent directory (`dirname ${LJ_LOG}`) doesn't exist."
    exit 1
  fi
}

start() {
 check_prereqs

  echo -n $"Starting $NAME: "

  daemon --check $NAME --pidfile $PID_FILE $DAEMON

  RETVAL=$?

  if [ $RETVAL -ne 0 ]; then
    echo_failure
    echo
  else
    PID=$(pgrep $NAME)
    echo -n $PID > $PID_FILE
    echo_success
    echo
  fi
  return $RETVAL
}

stop () {
  echo -n $"Stopping $NAME: "
  killproc -p $PID_FILE $NAME
  RETVAL=$?
  echo
  return $RETVAL
}

restart () {
  stop
  start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status -p $PID_FILE $NAME
    ;;
  restart)
    restart
    ;;
  *)
    echo "Usage: $0 {start|stop|status}"
    exit 2
    ;;
esac
exit $?

但是当我尝试启动它时出现此错误。

root@host [/etc/init.d]# service logstash-forwarder start
2014/02/10 21:16:36 publisher init
2014/02/10 21:16:36 Failed to open config file '': open : no such file or directory
/etc/logstash-forwarder/config: line 28: syntax error: unexpected end of file
/etc/logstash-forwarder/config: line 28: warning: syntax errors in . or eval will cause                 future versions of the shell to abort as Posix requires
ERROR: Unable to locate Lumberjack binary, make sure it's installed

我可以手动启动 lumberjack/opt/logstash-forwarder/bin/logstash-forwarder -config="/etc/logstash-forwarder/config"并且它可以工作。

这是配置文件:

{
"network": {
    "servers": [ "xyxyxyxy" ],
    "ssl certificate": "/etc/ssl/certs/logstash-forwarder.crt",
    "ssl key": "/etc/ssl/private/logstash-forwarder.key",
    "ssl ca": "/etc/ssl/certs/logstash-forwarder.crt"
  },
  "files": [
    {
      "paths": [ "/var/log/messages" ],
      "fields": { "type": "iptables" }
    },                                                                                                                                                                                                                
    {                                                                                                                                                                                                                 
      "paths": [ "/etc/httpd/logs/error_log" ],                                                                                                                                                                       
      "fields": { "type": "apache" }                                                                                                                                                                                  
    },                                                                                                                                                                                                                
    {                                                                                                                                                                                                                 
      "paths": [ "/var/log/maillog"],                                                                                                                                                                                 
      "fields": {"type": "mail"}                                                                                                                                                                                      
    },                                                                                                                                                                                                                
     {                                                                                                                                                                                                                
     "paths": ["/var/log/lfd.log"],                                                                                                                                                                                   
      "fields": {"type": "lfd"}                                                                                                                                                                                       
      }                                                                                                                                                                                                               

  ]                                                                                                                                                                                                                   
}

有人能帮我解决这个脚本吗?

答案1

这只是猜测,但我认为线路上存在问题。尝试移除它,看看会发生什么。

. /etc/logstash-forwarder/config

还可以尝试在指定二进制文件时使用引号“或'而不是反引号`。

相关内容