#!/usr/bin/python
import sys
import os
from sys import argv
DAMON='/opt/server/nginx/sbin/nginx'
CONFIG='/opt/server/nginx/conf/nginx.conf'
PIDFILE='/var/run/nginx/nginx.pid'
NGSTART='%s -c %s' %(DAMON,CONFIG)
NGSTOP='kill -QUIT `cat %s`' %PIDFILE
def n_start():
if os.path.isfile(PIDFILE):
print("nginx is already running")
else:
if os.system(NGSTART) == 0:
print("nginx is start ok")
def n_stop():
if os.path.isfile(PIDFILE):
if os.system(NGSTOP) == 0:
print("nginx is stop ok")
else:
print("nginx is not running")
def restart():
stop()
start()
if argv=="-h" or argv=="--help" or len(argv)==1:
print("Usage:%s{start|stop|restart}"%argv[0])
elif argv[1] == 'start':
n_start()
elif argv[1] == 'stop':
n_stop()
elif argv[1] == 'restart':
n_stop()
n_start()
else:
print("Usage: %s{start|stop|restart|reload}" %argv[0])
import sys
import os
from sys import argv
DAMON='/opt/server/nginx/sbin/nginx'
CONFIG='/opt/server/nginx/conf/nginx.conf'
PIDFILE='/var/run/nginx/nginx.pid'
NGSTART='%s -c %s' %(DAMON,CONFIG)
NGSTOP='kill -QUIT `cat %s`' %PIDFILE
def n_start():
if os.path.isfile(PIDFILE):
print("nginx is already running")
else:
if os.system(NGSTART) == 0:
print("nginx is start ok")
def n_stop():
if os.path.isfile(PIDFILE):
if os.system(NGSTOP) == 0:
print("nginx is stop ok")
else:
print("nginx is not running")
def restart():
stop()
start()
if argv=="-h" or argv=="--help" or len(argv)==1:
print("Usage:%s{start|stop|restart}"%argv[0])
elif argv[1] == 'start':
n_start()
elif argv[1] == 'stop':
n_stop()
elif argv[1] == 'restart':
n_stop()
n_start()
else:
print("Usage: %s{start|stop|restart|reload}" %argv[0])
本文转自 妙曼 51CTO博客,原文链接:http://blog.51cto.com/yanruohan/1937181,如需转载请自行联系原作者