Mercurial > logstash
annotate logstash.rc @ 4:29ffaf4e0a7f
keep 7 days of data; more readable init script
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 07 Mar 2013 21:24:02 -0800 |
parents | 796ac0b50dbf |
children | 6b7beb807d14 |
rev | line source |
---|---|
0 | 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 | |
3
796ac0b50dbf
add cron.daily index cleaning
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
32 ARGS="-jar ${JARNAME} agent --config ${CONFIGFILE} --log ${LOGFILE} -- web --backend elasticsearch://127.0.0.1/?local" |
0 | 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 | |
4
29ffaf4e0a7f
keep 7 days of data; more readable init script
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
50 pid=$( |
29ffaf4e0a7f
keep 7 days of data; more readable init script
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
51 exec sudo -u logstash /bin/bash - <<EOF |
29ffaf4e0a7f
keep 7 days of data; more readable init script
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
52 $JAVA $ARGS </dev/null >$LOGFILE 2>&1 & |
29ffaf4e0a7f
keep 7 days of data; more readable init script
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
53 echo \$! |
29ffaf4e0a7f
keep 7 days of data; more readable init script
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
54 EOF |
29ffaf4e0a7f
keep 7 days of data; more readable init script
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
55 ) |
29ffaf4e0a7f
keep 7 days of data; more readable init script
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
56 #pid=$(su logstash -c 'echo -e "'"$JAVA $ARGS"' </dev/null >'"$LOGFILE"' 2>&1 & \n echo \$!" | bash') |
0 | 57 echo $pid >$PIDFILE |
58 [ -n "$pid" ] && success $"$base startup" || failure $"$base startup" | |
59 } | |
60 | |
61 | |
62 # | |
63 # Function that stops the daemon/service | |
64 # | |
65 do_stop() { | |
66 killproc -p $PIDFILE logstash | |
67 } | |
68 | |
69 | |
70 case "$1" in | |
71 start) | |
72 echo -n "Starting $DESC: " | |
73 do_start | |
74 touch /var/lock/subsys/$base | |
75 ;; | |
76 stop) | |
77 echo -n "Stopping $DESC: " | |
78 do_stop | |
79 rm /var/lock/subsys/$base 2>/dev/null | |
80 rm $PIDFILE 2>/dev/null | |
81 ;; | |
82 restart) | |
83 echo -n "Restarting $DESC: " | |
84 do_stop | |
85 do_start | |
86 ;; | |
87 reload) | |
88 echo -n "Reloading $DESC: " | |
89 pid=$(cat $PIDFILE) | |
90 [ -n "$pid" ] && pkill -HUP -u logstash -P $pid | |
91 ;; | |
92 status) | |
3
796ac0b50dbf
add cron.daily index cleaning
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
93 echo -n "$base " |
0 | 94 status -p $PIDFILE |
95 ;; | |
96 *) | |
97 echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 | |
98 exit 3 | |
99 ;; | |
100 esac | |
101 | |
102 echo | |
103 exit 0 |