python33下运行的nginx服务启动脚本

简介:

#!/usr/bin/env python33
#coding:utf8
#description: this is nginx server in python33 on scripts
import sys,os,time

class nginxserver(object):
nginx_path = '/usr/local/nginx/sbin/nginx'
configfile = '/usr/local/nginx/conf/nginx.conf'
pidfile = '/usr/local/nginx/logs/nginx.pid'
nginx_start = '%s -c %s'%(nginx_path,configfile)
nginx_stop = r'kill -QUIT $(cat %s)' %pidfile
nginx_reload = 'kill -HUP $(cat %s)' %pidfile
nginx_log = 'kill -USR1 $(cat %s)' %pidfile
nginx_access = '/usr/local/nginx/logs'
def start(self):
if os.path.isfile(self.pidfile):
print('nginx is already running!')
else:
if os.system(self.nginx_start) == 0:
print('nginx starting is OK!')
else:
print('nginx starting is error!')
def stop(self):
if os.path.isfile(self.pidfile):
if os.system(self.nginx_stop) == 0:
print('nginx stop is OK!')
else:
print('nginx stoping is error!')
else:
print('nginx is not running!')
def reload(self):
if os.path.isfile(self.pidfile):
if os.system(self.nginx_reload) == 0:
print('nginx reading is OK')
else:
print('nginx reading is error')
else:
print('nginx is not running')
def relog(self):
if os.path.isfile(self.pidfile):
os.system('cd %s && mv access.log access.log.%s' %(self.nginx_access,time.strftime('%Y%m%d%H%M%S',time.localtime())))
if os.system(self.nginx_log) == 0:
print('nginx reloging is ok')
else:
print('nginx reloging is error')
else:
print('nginx is not running')
def restart(self):
self.stop()
self.start()
def status(self):
if os.path.isfile(self.pidfile):
print('nginx in running!')
os.system('lsof -i :80')
else:
print('nginx is not running!')
if name == 'main':
server = nginxserver()
if hasattr(server,sys.argv[1]): #查找实例中是否有次方法
func = getattr(server,sys.argv[1]) #生成一个函数执行内存地址
func()
else:
print("Usage: %s {start|stop|status|restart|reload|relog}" %sys.argv[0])


本文转自 80后小菜鸟 51CTO博客,原文链接:http://blog.51cto.com/zhangxinqi/2056483


相关文章
|
7天前
|
存储 Shell 区块链
怎么把Python脚本打包成可执行程序?
该文档介绍了如何将Python脚本及其运行环境打包成EXE可执行文件,以便在不具备Python环境的计算机上运行。首先确保Python脚本能够正常运行,然后通过安装PyInstaller并使用`--onefile`参数将脚本打包成独立的EXE文件。此外,还提供了去除命令行窗口和指定可执行文件图标的详细方法。这些步骤帮助用户轻松地将Python程序分发给最终用户。
怎么把Python脚本打包成可执行程序?
|
1天前
|
安全 JavaScript 前端开发
自动化测试的魔法:如何用Python编写你的第一个测试脚本
【8月更文挑战第41天】在软件的世界里,质量是王道。而自动化测试,就像是维护这个王国的骑士,确保我们的软件产品坚不可摧。本文将引导你进入自动化测试的奇妙世界,教你如何使用Python这把强大的魔法杖,编写出能够守护你代码安全的第一道防护咒语。让我们一起开启这场魔法之旅吧!
|
7天前
|
存储 Java 开发者
python脚本实现原理
【9月更文挑战第4天】python脚本实现原理
20 5
|
4天前
|
运维 监控 API
自动化运维:使用Python脚本进行日常管理
【9月更文挑战第6天】在现代的IT环境中,自动化运维已成为提升效率、减少人为错误的关键。本文将介绍如何通过Python脚本简化日常的运维任务,包括批量配置管理和日志分析。我们将从基础语法讲起,逐步深入到脚本的实际应用,旨在为读者提供一套完整的解决方案,以实现运维工作的自动化和优化。
11 1
|
8天前
|
运维 Linux 测试技术
自动化运维:使用Python脚本简化日常任务
【8月更文挑战第34天】在快节奏的IT环境中,自动化运维成为提升效率、降低错误率的关键。本文以Python脚本为例,展示如何通过编写简单的脚本来自动化日常运维任务,如批量更改文件权限、自动备份数据等。文章不仅提供代码示例,还探讨了自动化运维带来的益处和实施时应注意的问题。
|
9天前
|
运维 监控 网络安全
自动化运维:使用Python脚本简化日常任务
【8月更文挑战第33天】在本文中,我们将深入探讨如何通过Python脚本来自动化执行常见的运维任务。从基础的服务器健康检查到复杂的部署流程,Python因其简洁和功能强大的特性,成为自动化工具的首选。文章将展示编写Python脚本的基本方法,并通过实际示例演示如何应用于真实场景,旨在帮助读者提升效率,减少重复性工作。
|
8天前
|
运维 监控 Python
自动化运维:使用Python脚本简化日常任务
【8月更文挑战第34天】在数字化时代,高效运维成为企业竞争力的关键。本篇文章将引导你通过Python脚本实现自动化运维,从而提升工作效率和减少人为错误。我们将从简单的文件备份脚本开始,逐步深入到系统监控和自动报告生成,让你的日常工作更加轻松。
|
1天前
|
存储 数据采集 人工智能
探索Python编程之美——从基础到进阶
【9月更文挑战第9天】本文是一篇深入浅出的技术分享文章,旨在引导读者从零基础开始掌握Python编程。我们将通过生动的实例和代码示例,探讨Python的基本语法、数据结构、函数、模块以及面向对象编程等核心概念。无论你是初学者还是有一定经验的开发者,都能在这篇文章中找到有价值的内容。让我们一起开启Python编程之旅吧!
16 11
下一篇
DDNS