Logstash Service startup script
Recently in the elk, found that Logstash no SYSV type of service startup script, so according to a foreigner provided by the online template to modify their own
#添加用户useradd Logstash-m-s/sbin/Nologinmkdir/var/log/logstash/Chown-R logstash:logstash/var/log/logstash/Chown-R logstash:logstash/usr/local/logstash-2.0.0/VI/etc/init.d/logstash#!/bin/bash#### BEGIN INIT info# provides:logstash# Required-Start: $local _fs $remote _fs# Required-Stop: $local _fs $remote _fs# Default-start:2 3 4 5# Default-stop:s0 1 6# Short-description:logstash# description:starts Logstash as a daemon.# Author: [email protected]### END INIT InfoSource
/etc/init.d/Functionssource/lib/lsb/init-functions# Process namename=Logstashdesc="Logstash Daemon"# Location of Logstash fileslocation="/usr/local/logstash-2.0.0/"#根据实际安装路径修改CONFIG_DIR="/usr/local/logstash-2.0.0/"LOGFILE="/var/log/logstash/logstash.log"ScriptName=/etc/init.d/Logstashpidfile="/var/run/logstash-agent.pid"Lock_file=/var/lock/subsys/$NAMENAMEJAVA=Javadaemonjava=`whichJava ' # ExitifThe package isn't installedif[!-X"$DAEMONJAVA"]; Then{ Echo "couldn ' t find $NAMEJAVA"Exit About}fistart () {Echo-N"starting $DESC:" if["$ (PS aux|grep-e"*/usr/local/logstash*"|grep-v grep)"!=""]; Then Echo "$desc already running ...."Exit0 Else$LOCATION/bin/logstash-f $CONFIG _dir/logstash_agent.conf > $LOGFILE2>&1&RETVAL=$?Sleep 3 Echo if["$ (PS aux|grep-e"*/usr/local/logstash*"|grep-v grep)"!=""]; Then Echo "$DESC Started"[$RETVAL-eq0] &&Touch$LOCK _file return $RETVALfi fi}stop () {Echo-N $"Stop $DESC:" Killall$NAMEJAVA RETVAL=$?Sleep 3 Echo if["$ (PS aux|grep-eqi"*/usr/local/logstash*"|grep-v grep)"=""]; Then Echo "$DESC stoped"[$RETVAL-eq0] &&RM-f/var/lock/subsys/$NAME $PIDFILE return $RETVALfi}restart () {Stop start} Case " $" inchstart) Start; stop) stop;; restart) restart;; Status) status $NAMEJAVA RETVAL=$? ;; *) Echo$"Usage: $ {start|stop|restart|status}"RETVAL=1EsacExit $RETVALEOFchmod+x/etc/init.d/logstash# Set Boot Chkconfig--add Logstashchkconfig logstash on
If there is a wrong place, welcome everyone to shoot brick O (∩_∩) o
The copyright of this article is owned by the author and cannot be reproduced without the author's consent.
Logstash Service startup script