我正在尝试编写一个启动脚本,将 elastalert 作为服务启动。elastalert 使用 python 并启动如下:
python -m elastalert --verbose --rule rules_folder/frequency.yaml --config config.yaml
我一直在尝试使其与以下内容一起使用:
#!/bin/bash
# elastalert startup script for elastalert
# pidfile: /var/run/elastalert.pid
# chkconfig: 2345 99 01
NAME=elastalert
PIDFILE=/var/run/$NAME.pid
ELASTALERT_DIR=/elastalert/elastalert
ELASTALERT_USER=elastalert
CONFIG_FILE=$ELASTALERT_DIR/config.yaml
ELASTALERT=$ELASTALERT_DIR/$NAME
. /etc/rc.d/init.d/functions
case $1 in
start)
echo -n $"Starting $NAME: "
cd $ELASTALERT_DIR
daemon --pidfile="$PIDFILE" "$ELASTALERT --rule rules_folder/frequency.yaml --config $CONFIG_FILE &"
RETVAL=$?
pid=`ps -ef | grep python | grep elastalert | awk '{print $2}'`
if [ -n "$pid" ]; then
echo $pid > "$PIDFILE"
fi
;;
stop)
echo -n $"Stopping $NAME: "
killproc -p "$PIDFILE" -d 10 "$ELASTALERT"
RETVAL="$?"
echo
[ $RETVAL = 0 ] && rm -f "$PIDFILE"
;;
*)
echo "Usage: /etc/init.d/elastalert {start|stop}" ;;
esac
exit 0
当我尝试运行脚本时,出现以下错误:
virtualenvelastalert) [root@mplinux scripts]# elastalert Traceback(最近一次调用最后):文件“/virtualenvelastalert/bin/elastalert”,第 11 行,在 load_entry_point('elastalert==0.0.95', 'console_scripts', 'elastalert' )() 文件“/virtualenvelastalert/lib/python2.7/site-packages/elastalert-0.0.95-py2.7.egg/elastalert/elastalert.py”,第 1426 行,在主客户端 = ElastAlerter(args) 文件“ /virtualenvelastalert/lib/python2.7/site-packages/elastalert-0.0.95-py2.7.egg/elastalert/elastalert.py”,第 94 行,在init self.conf = load_rules(self.args) 文件“/virtualenvelastalert/lib/python2.7/site-packages/elastalert-0.0.95-py2.7.egg/elastalert/config.py”,第 373 行,在 load_rules conf = yaml_loader(文件名)文件“/virtualenvelastalert/lib/python2.7/site-packages/staticconf/loader.py”,第 161 行,在 yaml_loader 中,打开(文件名)为 fh:IOError:[Errno 2] 没有这样的文件或目录:'config.yaml'