# nano /usr/local/bin/collectd-server
将下列内容添加到collectd-server文件。
#!/bin/bash
PORT="8888"
case $1 in
start)
cd /usr/local/collectd-web/
python runserverpy 2> /tmp/collectdlog &
sleep 1
stat=`netstat -tlpn 2>/dev/null | grep $PORT | grep "python"| cut -d":" -f2 | cut -d" " -f1`
if [[ $PORT -eq $stat ]]; then
sock=`netstat -tlpn 2>/dev/null | grep $PORT | grep "python"`
echo -e "Server is still running:\n$sock"
else
echo -e "Server has stopped"
fi
;;
stop)
pid=`ps -x | grep "python runserverpy" | grep -v "color"`
kill -9 $pid 2>/dev/null
stat=`netstat -tlpn 2>/dev/null | grep $PORT | grep "python"| cut -d":" -f2 | cut -d" " -f1`
if [[ $PORT -eq $stat ]]; then
sock=`netstat -tlpn 2>/dev/null | grep $PORT | grep "python"`
echo -e "Server is still running:\n$sock"
else
echo -e "Server has stopped"
fi
;;
status)
stat=`netstat -tlpn 2>/dev/null |grep $PORT| grep "python" | cut -d":" -f2 | cut -d" " -f1`
if [[ $PORT -eq $stat ]]; then
sock=`netstat -tlpn 2>/dev/null | grep $PORT | grep "python"`
echo -e "Server is running:\n$sock"
else
echo -e "Server is stopped"
fi
;;
)
echo "Use $0 start|stop|status"
;;
esac
万一你更改了runserverpy脚本的PORT变量值,就要确保你相应地对该bash文件更改了端口变量。
11 一旦你构建了collectd-server脚本,添加执行权限,以便能够运行它。现在唯一剩下来的事情就是,以类似管理系统服务的方式来管理Collectd-web服务器,为此执行下列命令。
# chmod +x /usr/local/bin/collectd-server
# collectd-server start
# collectd-server status
# collectd-server stop一. 概述
TcpMonitor是Apache Axis中提供的一个tcp请求监视工具,可以用于监视>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)