启动多个logstash脚本
一台服务器上启动多个logstash脚本
# more logstash_click
#!/bin/sh
# Init script for logstash
# Maintained by Elasticsearch
# Generated by pleaserun.
# Implemented based on LSB Core 3.1:
# * Sections: 20.2, 20.3
#
### BEGIN INIT INFO
# Provides: logstash
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description:
# Description: Starts Logstash as a daemon.
### END INIT INFO PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/logstash/bin
export PATH if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi # adirname - return absolute dirname of given file
adirname() { odir=`pwd`; cd `dirname $1`; pwd; cd "${odir}"; }
MYNAME=`basename "$0"`
MYDIR=`adirname "$0"`
LS_LOG_DIR="${MYDIR}/logs"
LS_DATA_PATH="${MYDIR}/data"
LS_CONF_DIR="${MYDIR}/conf.d" name="${MYNAME}" LS_USER=elasticsearch
LS_GROUP=elasticsearch
LS_HOME=/usr/local/logstash
LS_HEAP_SIZE="256m"
#LS_LOG_DIR=/usr/local/logstash/logs
LS_LOG_FILE="${LS_LOG_DIR}/$name.log"
pidfile="${LS_LOG_DIR}/$name.pid"
#LS_CONF_DIR=/usr/local/logstash/conf.d
LS_OPEN_FILES=16384
LS_NICE=19
KILL_ON_STOP_TIMEOUT=${KILL_ON_STOP_TIMEOUT-0} #default value is zero to this variable but could be updated by user request
LS_OPTS="" [ -r /etc/default/$name ] && . /etc/default/$name
[ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name program=$LS_HOME/bin/logstash
args=" -f ${LS_CONF_DIR} --path.data=${LS_DATA_PATH} -l ${LS_LOG_FILE} ${LS_OPTS}" quiet() {
"$@" > /dev/null 2>&1
return $?
} start() { LS_JAVA_OPTS="${LS_JAVA_OPTS} -Djava.io.tmpdir=${LS_HOME}"
HOME=${LS_HOME}
export PATH HOME LS_HEAP_SIZE LS_JAVA_OPTS LS_USE_GC_LOGGING LS_GC_LOG_FILE # chown doesn't grab the suplimental groups when setting the user:group - so we have to do it for it.
# Boy, I hope we're root here.
SGROUPS=$(id -Gn "$LS_USER" | tr " " "," | sed 's/,$//'; echo '') if [ ! -z $SGROUPS ]
then
EXTRA_GROUPS="--groups $SGROUPS"
fi # set ulimit as (root, presumably) first, before we drop privileges
ulimit -n ${LS_OPEN_FILES} # Run the program!
nice -n ${LS_NICE} chroot --userspec $LS_USER:$LS_GROUP $EXTRA_GROUPS / sh -c "
cd $LS_HOME
ulimit -n ${LS_OPEN_FILES}
$program $args > ${LS_LOG_DIR}/$name.stdout" 2> "${LS_LOG_DIR}/$name.err" & # Generate the pidfile from here. If we instead made the forked process
# generate it there will be a race condition between the pidfile writing
# and a process possibly asking for status.
echo $! > $pidfile echo "$name started."
return 0
} stop() {
# Try a few times to kill TERM the program
if status ; then
pid=`cat "$pidfile"`
echo "Killing $name (pid $pid) with SIGTERM"
ps -ef |grep $pid |grep -v 'grep' |awk '{print $2}' | xargs kill -9
# Wait for it to exit.
for i in 1 2 3 4 5 6 7 8 9 ; do
echo "Waiting $name (pid $pid) to die..."
status || break
sleep 1
done
if status ; then
if [ $KILL_ON_STOP_TIMEOUT -eq 1 ] ; then
echo "Timeout reached. Killing $name (pid $pid) with SIGKILL. This may result in data loss."
kill -KILL $pid
echo "$name killed with SIGKILL."
else
echo "$name stop failed; still running."
return 1 # stop timed out and not forced
fi
else
echo "$name stopped."
fi
fi
} status() {
if [ -f "$pidfile" ] ; then
pid=`cat "$pidfile"`
if kill -0 $pid > /dev/null 2> /dev/null ; then
# process by this pid is running.
# It may not be our pid, but that's what you get with just pidfiles.
# TODO(sissel): Check if this process seems to be the same as the one we
# expect. It'd be nice to use flock here, but flock uses fork, not exec,
# so it makes it quite awkward to use in this case.
return 0
else
return 2 # program is dead but pid file exists
fi
else
return 3 # program is not running
fi
} configtest() {
# Check if a config file exists
if [ ! "$(ls -A ${LS_CONF_DIR}/* 2> /dev/null)" ]; then
echo "There aren't any configuration files in ${LS_CONF_DIR}"
return 1
fi HOME=${LS_HOME}
export PATH HOME test_args="-t -f ${LS_CONF_DIR} ${LS_OPTS} "
$program ${test_args}
[ $? -eq 0 ] && return 0
# Program not configured
return 6
} case "$1" in
start)
status
code=$?
if [ $code -eq 0 ]; then
echo "$name is already running"
else
start
code=$?
fi
exit $code
;;
stop) stop ;;
force-stop) force_stop ;;
status)
status
code=$?
if [ $code -eq 0 ] ; then
echo "$name is running"
else
echo "$name is not running"
fi
exit $code
;;
reload) reload ;;
restart)
stop && start
;;
check)
configtest
exit $?
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|check}" >&2
exit 3
;;
esac exit $?
启动多个logstash脚本的更多相关文章
- 一键启动NameNode和DataNode--shell脚本
使用shell脚本,一键启动hadoop中的NameNode和DataNode.分为普通版和装逼版.装逼版较普通版多了很多判断和信息提示,当然主要还是为了我联系shell脚本而写的. 如果想实现复用, ...
- 老李推荐:第8章5节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-运行测试脚本
老李推荐:第8章5节<MonkeyRunner源码剖析>MonkeyRunner启动运行过程-运行测试脚本 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化 ...
- SQLServer启动和关闭bat脚本
原文:SQLServer启动和关闭bat脚本 安装完毕SQL SERVER 2005后,会默认自动启动SQL Server等几个服务,这几个服务比较占用系统资源.当不运行SQL Server时,最 ...
- .net 程序通过 crontab 无法启动,手动执行脚本可以启动
一.问题描述 .net 网关程序需要设置定时重启,按照日常操作先把正在运行的 PID kill 掉后,再执行启动服务. 把脚本放到 crontab 计划任务上,可以把服务 PID kill 掉,但无法 ...
- Linux 解决数量庞大wildfly容器启动与停止的脚本
一.问题 因公司业务的发展,后台架构的变更,导致测试环境(Linux)部署与管理困难成倍增长,duang的一下,增加N倍.进入正题说问题: 问题1. 测试环境包含普通用户环境.开发者用户环境,原来只 ...
- telnet登录路由器启动服务的shell脚本
因为在测试中经常要telnet登录到路由器中去配置环境启动路由器,每次都输入一遍命令太麻烦了,想着写一个shell脚本实现自动登录.配置环境.启动服务的过程. 脚本实现是使用expect来实现的,所以 ...
- Linux下一个Redis启动/关闭/重新启动服务脚本
脚本功能: 实现redis单机多实例情况下的正常启动.关闭.重新启动单个redis实例.完毕系统标准服务的下面经常使用功能: start|stop|status|restart 注:redis程序代 ...
- OpenWrt启动过程分析+添加自启动脚本【转】
一.OpenWrt启动过程分析 转自: http://www.eehello.com/?post=107 总结一下OpenWrt的启动流程:1.CFE->2.linux->3./etc/p ...
- linux 程序启动与停止管理脚本
公司接了一个第三方的系统,基于linux写的几个程序,一共有9个部件,第三方没有给脚本,每次启动或停止都得一个一个手工去停止或修改.......,这里稍微鄙视下. 没办法,求人还不如自己动手写, 需求 ...
随机推荐
- 【公众号系列】SAP的新零售
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[公众号系列]SAP的新零售 写在前面 还是 ...
- 【转载】xilinx 高速收发器Serdes深入研究
此篇文章深入浅出介绍了关于高速串行收发器的几个重要概念和注意事项,为方便知识点复习总结和后续查阅特此转载,原文标题及链接为:xilinx 高速收发器Serdes深入研究 - CSDN博客 http ...
- Pycharm 消除波浪线
转载:https://blog.csdn.net/youyouran12314/article/details/77719261 Pycharm环境下显示 在代码中显示许多波浪线,查看详情显示Spel ...
- 做为一个Python程序员的基本素养
今天在学习的过程中,明白了一些不是Python标准所必须要做的事情,二是做为一个合格的Python程序员应该所遵从的一些规范 分享给大家,有不足的地方请大家指正,此下是我学习的一点心得: 1.在给变量 ...
- hashlib模块
老师博客:http://www.cnblogs.com/Eva-J/articles/7228075.html#_label12 摘要算法 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个 ...
- 数据库【mysql】之pymysql
安装模块 pip install pymysql 导入模块 import pymysql 创建链接 conn = pymysql.connect(host=') 创建索引 cursor = conn. ...
- 入门 Webpack,一篇就够了
阅读本文之前,先看下面这个webpack的配置文件,如果每一项你都懂,那本文能带给你的收获也许就比较有限,你可以快速浏览或直接跳过:如果你和十天前的我一样,对很多选项存在着疑惑,那花一段时间慢慢阅读本 ...
- Linux 实例常用内核网络参数介绍与常见问题处理
本文总结了常见的 Linux 内核参数及相关问题.修改内核参数前,您需要: 从实际需要出发,最好有相关数据的支撑,不建议随意调整内核参数. 了解参数的具体作用,且注意同类型或版本环境的内核参数可能有所 ...
- 性能测试监控平台:InfluxDB+Grafana+Jmeter
前面的博客介绍了InfluxDB.Telegraf.Grafana的安装和使用方法,这篇博客,介绍下如何利用这些开源工具搭建性能测试监控平台... 前言 性能测试工具jmeter自带的监视器对性能测试 ...
- 复杂度定义 The Definition of Complexity
The upper bound Big-O: Definition: f(n) is in O(g(n)) if there are constants c0 and N0 such that f ...