-1

I'm using lumberjack shipper for logstash. I'm in need of init.d script to start lumberjack on centos system. I have the script for debian based systems but can't get one on Centos to work.

I have this script right now:

#!/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 $?

But I'm getting this error when I try to start it.

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

I can start lumberjack manually with /opt/logstash-forwarder/bin/logstash-forwarder -config="/etc/logstash-forwarder/config" and it works.

Here is the config file:

{
"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"}                                                                                                                                                                                       
      }                                                                                                                                                                                                               

  ]                                                                                                                                                                                                                   
}

Can anyone help me out with this script ?

Katherine Villyard
  • 18,550
  • 4
  • 37
  • 59
Pracovek
  • 11
  • 1
  • 2
    It looks like your /etc/logstash-forwarder/config is jacked up. can you post that. Also what arguments do you use to run it manually? – Steve Butler Feb 10 '14 at 21:36
  • Hi @SteveButler This is my config http://pastebin.com/Up7SVY79 and I start lumberjack with /opt/logstash-forwarder/bin/logstash-forwarder -config="/etc/logstash-forwarder/config" which works fine. Although, if I close my console, it also kills process. – Pracovek Feb 10 '14 at 21:44
  • 1
    I edited your post to add the info Steve Butler requested to the post itself. – Katherine Villyard Feb 10 '14 at 22:09
  • OK, so this is a wild guess, but comparing the working command to your script, are you missing an equal sign? 'DAEMON="nohup ${LJ_BIN} -config=${LJ_CONFIG} ${LJ_OPTS} >>${LJ_LOG} 2>&1 &"' – Katherine Villyard Feb 10 '14 at 22:31
  • 1
    No, that syntax is correct for logstash, at least on my boxen it is without the '='. I'm actually wondering if the config syntax is correct, or conversely if it's in DOS format or something – Steve Butler Feb 10 '14 at 23:20

1 Answers1

0

It's just a a guess, but I think it has a problem on the line. Try removing it, see what happens.

. /etc/logstash-forwarder/config

Also try using quotes " or ' instead of the backtick ` where you specify your binary.

Steve Butler
  • 1,016
  • 9
  • 19
  • Hi @SteveButler I tried and I'm still getting the same error. Only difference is that now I'm getting error on line 34 instead on line 28 2014/02/11 19:08:49 publisher init 2014/02/11 19:08:49 Failed to open config file '': open : no such file or directory /etc/init.d/logstash-forwarder: line 34: /etc/logstash- forwarder/config: Permission denied ERROR: Unable to locate Lumberjack binary, make sure it's installed. – Pracovek Feb 11 '14 at 18:11