wangluo010 发表于 2018-11-16 07:09:17

nginx启动python脚本

#!/usr/bin/env python  
# -*- coding:utf-8 -*-
  

  
import sys
  
import os
  
from sys import    argv
  

  
DAEMON='/usr/local/nginx/sbin/nginx'
  
CONFIGFILE='/usr/local/nginx/conf/nginx.conf'
  
PIDFILE='/usr/local/nginx/logs/nginx.pid'
  

  

  
NGSTART='%s -c %s' % (DAEMON,CONFIGFILE)
  
NGSTOP='kill -QUIT `cat %s`' %PIDFILE
  

  
def n_start():
  
    if os.path.isfile(PIDFILE):
  
      print "nginx is already running!"
  
    else:
  
      ifos.system(NGSTART) == 0:
  
            print "nginx start is ok!"
  

  
def n_stop():
  
    if os.path.isfile(PIDFILE):
  
      if os.system(NGSTOP) == 0:
  
            print "nginx stop is ok!"
  
    else:
  
      print "nginx is not running!"
  

  
def n_restart():
  
    stop()
  
    start()
  

  
if argv == "-h" or argv == "--help" or len(argv)==1:
  

  
    print "Usage: %s {start|stop|restart|reload}"% argv
  
elif argv == 'start':
  
    n_start()
  
elif argv == 'stop':
  
    n_stop()
  
elif argv == 'restart':
  
    n_stop()
  
    n_start()
  

  
else:
  
      print "Usage: %s {start|stop|restart|reload}"% argv


页: [1]
查看完整版本: nginx启动python脚本