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


相关文章
|
15天前
|
应用服务中间件 网络安全 nginx
快速上手!使用Docker和Nginx部署Web服务的完美指南
快速上手!使用Docker和Nginx部署Web服务的完美指南
|
15天前
|
存储 Ubuntu 应用服务中间件
【Nginx】centos和Ubuntu操作系统下载Nginx配置文件并启动Nginx服务详解
【Nginx】centos和Ubuntu操作系统下载Nginx配置文件并启动Nginx服务详解
22 1
|
1天前
|
缓存 人工智能 算法
编写高效的Python脚本:性能优化的策略与技巧
编写高效的Python脚本需要综合考虑多个方面,包括代码结构、数据结构和算法选择等。本文将探讨在Python编程中提高脚本性能的方法,包括优化数据结构、选择合适的算法、使用Python内置函数以及通过并行和异步编程提升效率。这些技巧旨在帮助开发者在不同应用场景中编写出高性能的Python代码。
|
2天前
|
缓存 Shell 开发工具
[oeasy]python0016_在vim中直接运行python程序
在 Vim 编辑器中,可以通过`:!`命令来执行外部程序,例如`:!python3 oeasy.py`来运行Python程序。如果想在不退出Vim的情况下运行当前编辑的Python文件,可以使用`%`符号代表当前文件名,所以`:!python3 %`同样能运行程序。此外,可以使用`|`符号连续执行命令,例如`:w|!python3 %`会先保存文件(`w`)然后运行Python程序。这样,就可以在不离开Vim的情况下完成编辑、保存和运行Python程序的流程。
14 0
|
10天前
|
SQL DataWorks 安全
DataWorks产品使用合集之DataWorks资源里python运行时候,查看中途打印日志如何解决
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
25 0
|
11天前
|
弹性计算 应用服务中间件 Shell
编写nginx 启动脚本
【4月更文挑战第29天】
11 1
|
11天前
|
测试技术 Python
python运行集成测试
【4月更文挑战第22天】
10 1
|
12天前
|
存储 网络安全 数据安全/隐私保护
【专栏】Python 网络设备管理中,`ConnectHandler`(Paramiko库)和`telnetlib`模块常用于设备交互。
【4月更文挑战第28天】Python 网络设备管理中,`ConnectHandler`(Paramiko库)和`telnetlib`模块常用于设备交互。`ConnectHandler`简化SSH连接,便于与网络设备交互,而`telnetlib`是Python内置模块,支持Telnet协议的远程登录操作。两者都提供命令执行和响应接收功能。示例代码展示了如何使用它们获取防火墙设备的版本信息,降低了代码复杂度,提高了可读性和维护性。
|
12天前
|
网络安全 数据安全/隐私保护 Python
【专栏】如何使用 Python 编写脚本批量备份交换机配置
【4月更文挑战第28天】本文介绍如何使用 Python 编写脚本批量备份交换机配置。主要步骤包括了解交换机命令和接口,安装 `paramiko` 库,获取交换机登录信息。脚本实现分为建立 SSH 连接,执行备份命令并保存结果。示例脚本中,定义了 `backup_switch_config` 函数遍历交换机列表进行备份,每次备份后等待一段时间。此方法能有效提高网络管理效率。
|
12天前
|
运维 监控 Serverless
Serverless 应用引擎产品使用之阿里函数计算中在自定义环境下用debian10运行django,用官方层的python3.9,配置好环境变量后发现自定义层的django找不到了如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
21 3