首页 > 代码库 > logstash服务启动脚本
logstash服务启动脚本
logstash服务启动脚本
最近在弄ELK,发现logstash没有sysv类型的服务启动脚本,于是按照网上一个老外提供的模板自己进行修改
#添加用户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: S 0 1 6# Short-Description: Logstash# Description: Starts Logstash as a daemon.# Author: christian.paredes@sbri.org### 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=`which java`# Exit if the package is not installedif [ ! -x "$DAEMONJAVA" ]; then{ echo "Couldn‘t find $NAMEJAVA" exit 99}fistart() { echo -n "Starting $DESC : " if [ "$(ps aux|grep -E "*/usr/local/logstash*" |grep -v grep)" != "" ];then echo "$desc already running...." exit 0 else $LOCATION/bin/logstash -f $CONFIG_DIR/logstash_agent.conf >$LOGFILE 2>&1 & RETVAL=$? sleep 3 echo if [ "$(ps aux|grep -E "*/usr/local/logstash*" |grep -v grep)" != "" ];then echo "$DESC Started " [ $RETVAL -eq 0 ] && touch $LOCK_FILE return $RETVAL fi 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 -eq 0 ] && rm -f /var/lock/subsys/$NAME $PIDFILE return $RETVAL fi }restart() { stop start}case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status $NAMEJAVA RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|status}" RETVAL=1esacexit $RETVALEOFchmod +x /etc/init.d/logstash#设置开机启动chkconfig --add logstashchkconfig logstash on
如有不对的地方,欢迎大家拍砖o(∩_∩)o
本文版权归作者所有,未经作者同意不得转载。
logstash服务启动脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。