comparison logstash.rc @ 0:df4952a2fb06

initial version
author Carl Byington <carl@five-ten-sg.com>
date Fri, 01 Mar 2013 14:58:09 -0800
parents
children 796ac0b50dbf
comparison
equal deleted inserted replaced
-1:000000000000 0:df4952a2fb06
1 #!/bin/bash
2 #
3 # /etc/rc.d/init.d/logstash
4 #
5 # Starts Logstash as a daemon
6 #
7 # chkconfig: 2345 20 80
8 # description: Starts Logstash as a daemon
9 # pidfile: /var/run/logstash.pid
10
11 ### BEGIN INIT INFO
12 # Provides: logstash
13 # Required-Start: $local_fs $remote_fs
14 # Required-Stop: $local_fs $remote_fs
15 # Default-Start: 2 3 4 5
16 # Default-Stop: S 0 1 6
17 # Short-Description: Logstash
18 # Description: Starts Logstash as a daemon.
19 # Modified originally from https://gist.github.com/2228905#file_logstash.sh
20
21 ### END INIT INFO
22
23 # Amount of memory for Java
24 #JAVAMEM=256M
25
26 export HOME=/var/lib/logstash
27 DESC="Logstash Daemon"
28 JAVA=$(which java)
29 CONFIGFILE=/etc/logstash/logstash.conf
30 LOGFILE=/var/log/logstash/logstash.log
31 JARNAME=/usr/local/bin/logstash.jar
32 ARGS="-jar ${JARNAME} agent -vvv --config ${CONFIGFILE} --log ${LOGFILE} -- web --backend elasticsearch://127.0.0.1/?local"
33 SCRIPTNAME=/etc/rc.d/init.d/logstash
34 PIDFILE=/var/run/logstash.pid
35 base=logstash
36
37 # Exit if java is not installed
38 if [ ! -x "$JAVA" ]; then
39 echo "Couldn't find $JAVA"
40 exit 99
41 fi
42
43 . /etc/init.d/functions
44
45 #
46 # Function that starts the daemon/service
47 #
48 do_start() {
49 cd $HOME
50 pid=$(su logstash -c 'echo -e "'"$JAVA $ARGS"' </dev/null >'"$LOGFILE"' 2>&1 & \n echo \$!" | bash')
51 echo $pid >$PIDFILE
52 [ -n "$pid" ] && success $"$base startup" || failure $"$base startup"
53 }
54
55
56 #
57 # Function that stops the daemon/service
58 #
59 do_stop() {
60 killproc -p $PIDFILE logstash
61 }
62
63
64 case "$1" in
65 start)
66 echo -n "Starting $DESC: "
67 do_start
68 touch /var/lock/subsys/$base
69 ;;
70 stop)
71 echo -n "Stopping $DESC: "
72 do_stop
73 rm /var/lock/subsys/$base 2>/dev/null
74 rm $PIDFILE 2>/dev/null
75 ;;
76 restart)
77 echo -n "Restarting $DESC: "
78 do_stop
79 do_start
80 ;;
81 reload)
82 echo -n "Reloading $DESC: "
83 pid=$(cat $PIDFILE)
84 [ -n "$pid" ] && pkill -HUP -u logstash -P $pid
85 ;;
86 status)
87 status -p $PIDFILE
88 ;;
89 *)
90 echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
91 exit 3
92 ;;
93 esac
94
95 echo
96 exit 0