首先 先安装nginx
echo '[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1' >>/etc/yum.repos.d/nginx.repo
yum install nginx -y
第二 测试python 监控nginx 进程
mkdir -p /usr/local/nignx/logs
touch /usr/local/nignx/logs/nginx.lock
[root@c ~]# cat chkng
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import os
pf ="/usr/local/nignx/logs/nginx.lock"
os.system("ps -A|grep nginx>%s"% pf)
if not(os.path.getsize(pf)):
os.system("/etc/init.d/nginx restart")
[root@c ~]# chmod +x chkng
[root@c ~]#crontab -l
*/5 * * * * /root/chkng
[root@c ~]# /etc/init.d/nginx stop
停止 nginx: [确定]
[root@c ~]# netstat -nlpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1782/portmap
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2106/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2137/sendmail
tcp 0 0 0.0.0.0:732 0.0.0.0:* LISTEN 1822/rpc.statd
[root@c ~]# date
2013年 06月 03日 星期一 05:04:34 CST
[root@c ~]# netstat -nlpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1782/portmap
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17572/nginx
参考
http://wiki.nginx.org/Install
http://www.91python.com/archives/317